Get file size in .bat

ordi -  
cs-bilou Posted messages 836 Status Member -
Hello,

I would like to write a .bat file that returns a message when a file is empty.

Could I please get some help as I am still a novice in .bat.

Thank you in advance.
Configuration: Windows XP Firefox 2.0.0.2

2 answers

ben
 
Hello computer,

I've done quite a bit of searching and found this:

call :size_file file_to_check.txt
if %size%==0 echo file empty>>log_file.txt

:size_file
set size=%~z1
goto exit
:exit

The call lets you invoke the size_file function by passing it the file to check as a parameter. Your script then pauses and looks for the function :size_file. With the set function, you assign the value of your file size to the variable size (for reference, if you right-click on your file and then properties, the size returned is the one written next to size and not size on disk). The variable %~z1 corresponds to the size of your file. Then the goto exit allows you to exit the function. Your script then resumes where it left off, that is at the IF level. There, you test your value and display your message. Here, I display it in a log file.

There you go.
8
Nicoco
 
Hello,

do you know the command to do the same thing but on a complete folder?

Example:

if c:/folder is greater than 2 bytes, execute the command



thank you in advance
0
cs-bilou Posted messages 836 Status Member 164
 
Here you go.
This is for all the MP3 files:

@echo off for %%i in (*.mp3) do ( echo %%~ni weighs %%~zi bytes. ) pause


Bilou
--
There are days you really shouldn't mess with me.
And there are days, every day!
2