Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Send to File: Directory, Subdir Contents + File Info  (Read 8407 times)

0 Members and 1 Guest are viewing this topic.

rjbinney

    Topic Starter


    Adviser
  • Disarmingly Good-looking
  • Experience: Familiar
  • OS: Windows 11
Send to File: Directory, Subdir Contents + File Info
« on: November 20, 2022, 11:00:58 PM »
Trying to get a TXT file with:
- Full filepath+filename
- File size
- Created date

I would like to be able to do this for a master directory, and have it do it automatically for all the subdirs.

If I do:
Code: [Select]
dir /s >Directory.txt
I get a nice list of files + File info, but not the file path.

Quote
Directory of B:\Master\Subdirectory 1
11/19/2022 22:04 <DIR> .
11/19/2022 22:04 <DIR> ..
03/10/2014 18:14 43,309,056 00000.MTM
03/10/2014 18:16 54,355,968 00001.MTM
03/10/2014 18:17 46,884,864 00002.MTM

 Directory of B:\Master\Subdirectory 1\Double-Sub

11/19/2022  22:34    <DIR>          .
11/19/2022  22:34    <DIR>          ..
03/31/2014  02:10         5,157,601 S1710001.JPG
03/31/2014  02:10         5,170,611 S1710002.JPG
03/31/2014  03:07         5,023,670 S1710003.JPG

If I do
Code: [Select]
dir /s /b >PathList.txt
I get
Quote
B:\Master\Subdirectory 1\00000.MTM
B:\Master\Subdirectory 1\00001.MTM
B:\Master\Subdirectory 1\00002.MTM
B:\Master\Subdirectory 1\Double-Sub\S1710001.JPG
B:\Master\Subdirectory 1\Double-Sub\S1710002.JPG
B:\Master\Subdirectory 1\Double-Sub\S1710003.JPG

Without the file info.

What I'd like is:
Quote
03/10/2014 18:14       43,309,056 B:\Master\Subdirectory 1\00000.MTM
03/10/2014 18:16       54,355,968 B:\Master\Subdirectory 1\00001.MTM
03/10/2014 18:17       46,884,864 B:\Master\Subdirectory 1\00002.MTM
03/31/2014  02:10       5,157,601   B:\Master\Subdirectory 1\Double-Sub\S1710001.JPG
03/31/2014  02:10         5,170,611   B:\Master\Subdirectory 1\Double-Sub\S1710002.JPG
03/31/2014  03:07         5,023,670   B:\Master\Subdirectory 1\Double-Sub\S1710003.JPG

Anything in CMD, Win 11, or an app that can help?
Dan: You're gonna need to get someone to fix my computer.                     Kim: What's wrong with it?                     Dan: It's in several pieces on my floor.

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: Send to File: Directory, Subdir Contents + File Info
« Reply #1 on: November 21, 2022, 12:25:57 AM »
This is a bit closer to what you want.


Code: [Select]
@echo off & for /f %a in ('dir /s /b') do echo %~ta %~za %~fa
Size doesn't have commas and there's no good way (I don't think) of right-padding the size so that things line up in the output text file. It's also rather slow, though assuming it doesn't need to be run frequently that probably isn't of great concern.

You could use semicolons instead of spaces between the variables in the echo, then you could import the file as a CSV into Excel or another spreadsheet program for easier review if necessary.
I was trying to dereference Null Pointers before it was cool.

rjbinney

    Topic Starter


    Adviser
  • Disarmingly Good-looking
  • Experience: Familiar
  • OS: Windows 11
Re: Send to File: Directory, Subdir Contents + File Info
« Reply #2 on: November 21, 2022, 01:03:32 PM »
Thanks. This just gave me a long list of the first 12 characters of the filepath onscreen...

I will want to import this into Excel. Sorry to be dense, where would I put the semicolons to create that file? (I'm not sure what the "variables" are... Would it be:
Quote
@echo off & for /f %a in ('dir /s /b') do echo %~ta;%~za;%~fa

And where do I specify the name of the output file?
Dan: You're gonna need to get someone to fix my computer.                     Kim: What's wrong with it?                     Dan: It's in several pieces on my floor.

Hackoo



    Hopeful
  • Thanked: 42
  • Experience: Expert
  • OS: Windows 10
Re: Send to File: Directory, Subdir Contents + File Info
« Reply #3 on: November 21, 2022, 11:15:52 PM »
Hi  ;)
You can write a batch file with some commands from PowerShell, like this one :
Code: [Select]
@echo off
Title Export Directory Information to CSV File using Powershell and Batch
Set MainDirectory="C:\Path of your Main Directory to be changed to yours\"
Set CSV_File="%AppData%\FilesInfos.csv"
Powershell -C "LS -path "%MainDirectory%" -Recurse | where {!$_.PSIsContainer} | Select-object LastWriteTime,Length,FullName | export-csv -encoding unicode -notypeinformation -path "%CSV_File%""
If Exist %CSV_File% Start "" %CSV_File%