0

I want to get a file containing a listing, one per line, of all files in all directories for all drives attached to my Windows 11 PC.

The lines should each contain the complete file name, size and last date modified. For example:

S:\big\1-ISO\cloudready-free-64bit.zip 1262746656 07/13/2021 16:19:04

This format would also be satisfactory:

107K 2019-12-08 10:52 S:\big\1-ISO\cloudready-free-64bit.zip

I have a batch file that loops through all the thumb drives attached to my Windows 11 PC. Something like:

for %%B in (D E F G H I J K L M N O P Q R S T U V) DO CALL 2ndBatchFile.BAT %%B

For each drive it finds, the batch file calls a second batch file which outputs a list of files, (including path), on the drive, (along with the file size and date), to a txt file with a name based on a file in the root directory of the drive. The following line in the called batch file does work:

for /f "usebackq delims=|" %%a in (`dir /b/s/a-d "%1:\"`) do @echo "%%~fa" # %%~za : %%~ta >>C:\temp\%DD%_DIR.TXT

The %1 refers to the drive letter, and the %DD% variable is created by using a specific file name in the drive's root directory.

The batch file is very slow when there are many files.

I saw a mention in a StackOverflow question, ("List files with path and file size only in Command Line"), of using a PowerShell command to create a file name with the Full Name, and size.

So I got a Command Prompt, typed Powershell, then changed to the correct thumb drive letter and then excuted the following command:

gci -rec -file|%{"$($_.Fullname) $($_.Length) $($_.LastWriteTime)"} >filelist.txt

The filelist.txt file looked list this, which is what I wanted.

S:\big\1-ISO\gparted-live-1.3.1-1-i686.iso 400556032 07/23/2021 19:36:14
S:\big\1-ISO\rescue_system-common-en.exe 295619320 07/21/2021 19:07:20
S:\big\1-ISO\systemrescue-8.04-i686.iso 757071872 07/24/2021 13:17:50

But I don't know PowerShell, and I don't know to integrate the above snippet into my batch file.

Can it be done?

Compo
  • 36,585
  • 5
  • 27
  • 39
  • On your first point, I would use the DIR command (which runs very fast), but I can't find a set of options that let's me recurse an entire tree and let me have on a single line the full path and file name along with a file size and date. DIR with /s/b gives me the full path and name, but not date or time. But without the /b I can't get the full path and name. On your second point, I will continue to scroll though stackoverflow looking for the exact syntax I need. I probably need to learn more about Powershell, especially the -force option. Thanks. – user2574126 Jul 23 '23 at 03:20
  • ```%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -Command "Get-ChildItem . -File -Force -Recurse | ForEach-Object { \"$($_.FullName) $($_.Length) $($_.LastWriteTime)\" }" 1>>"C:\temp\%DD%_DIR.TXT"``` – Compo Jul 23 '23 at 14:24

0 Answers0