Question Get file sizes in directory.

Apr 29, 2019
9
0
10
0
Good morning,

I am using a batch file.

I would like to get the file sizes for each of the files within a directory.

At present I use this which does exactly what I want except for giving me the file size at the end of each file.

dir /b /a:-d > File2.txt

Thanks in advance.
 
Apr 29, 2019
9
0
10
0
del file2.txt
for /f "tokens=*" %A in ('dir /b /a:-d') do echo %~nxA %~zA >>file2.txt
Thanks for the reply SkyNetRising, it is appreciated.

I put the batch code in the folder that I want the information for but unfortunately it doesn't create the file2.txt in the same folder!

I have searched for the file but I am unable to find it!

Thanks in advance.
 
Apr 29, 2019
9
0
10
0
If you execute those commands from bat file, then you must use "%%" instead of single "%".

del file2.txt
for /f "tokens=*" %%A in ('dir /b /a:-d') do echo %%~nxA %%~zA >>file2.txt
Unfortunately it doesn't work using your code!

This works from the cmd prompt . . .

for /f "tokens=*" %A in ('dir /b /a:-d') do echo %~nxA %~zA >> C:\users\system-admin\downloads\file99.txt

But I want to be able to run it within the folder itself [via a batch script] and output the details to a .txt within the same folder.

Thanks for your time on this, it is appreciated.
 

Mandark

Distinguished
i just tested the code supplied for the batch file, it works. if it isn't working for you , something is amiss in you windows.

for /f "tokens=*" %%A in ('dir /b /a:-d') do echo %%~nxA %%~zA >>file2.txt

and it creates the text file in the same directory you run the batch file in.
 
Apr 29, 2019
9
0
10
0
Well that is bizarre. I started from scratch and it works!

One final question please. How can I format the file size to show with thousand separators please. The /C doesn't seem to work!

Thanks in advance.
 
Apr 29, 2019
9
0
10
0
Using DIR /b /s /a:-d produces this for example . . .

E:\Folder_Name\File_Name.mkv

. . . which is great.

But I want it to produce the above with the file size [possibly with thousand seperator].

You gave me this . . .

/f "tokens=*" %%A in ('dir /b /s /a:-d') Do echo %%~nxA %%~zA >> "Master.txt"

. . . which does indeed give the file size but unfortunately leaves out the . . .

E:\Folder_Name\

. . . bit at the beginning.

Any help will be greatly appreciated.

Thanks in advance.
 

ASK THE COMMUNITY