Solved Empty folder size of 0 not getting displayed using batch

February 1, 2014 at 12:55:48
Specs: Windows 7
Got a batch file which will check the file size of a file\folder and print it in a seperate txt

Eg: Here's a line from my batch

FOR /F "usebackq" %%A IN ('%filename1%') DO set filesize1=%%~zA

echo %filename1% %filesize1% >>u.txt

Contents of U.txt

c:\work 0
c:\pictures\j1.jpg 4374
c:\pictures\tree.jpg 352
c:\windows\sol.exe 5344

The numbers on the right represent the size in bytes of every file. The "work" folder is empty, thus it shows 0.

The issue is sometimes depending on what drive the batch checks, what drive I run it from, etc, an empty folder will end up showing without the 0 on its right such as:

contents of u.txt:

c:\work
c:\pictures\j1.jpg 4374
c:\pictures\tree.jpg 352
c:\windows\sol.exe 5344

There may be a hundred reasons why that may happen but I just need to know How to automatically put a 0 in front of every empty folder in my txt file because without a number in the front of the folder , the batch will crash as the number needs to be set as a variable later on.


See More: Empty folder size of 0 not getting displayed using batch

Report •

#1
February 1, 2014 at 19:17:20
might work, not tested. Between lines one and two of your extract:
set /a filesize+=0

Note do NOT enclose var FILESIZE with percents in the "set /a" operation.


Report •

#2
February 4, 2014 at 07:41:03
✔ Best Answer
You might be able to use an if defined to ensure that the variable is set.

::mike


Report •

#3
February 10, 2014 at 13:52:28
Bwah ha ha, that has to be one of the shortest best answers ever. :) hope it fixed the problem.

::mike


Report •
Related Solutions


Ask Question