Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command for getting the file size

Could anybody please tell me a shell command for Windows 7 which would take a file path as argument and return the size of that file - Something like:

fileSize.cmd file.txt

...which will give me 1KB.

One question in SO noted the command echo %~z1, but for this, I have to write a separate batch file and use this command in it. I was thinking of modifying my existing bat file and incorporate this command somehow. My batch file looks like this:

p4 diff //sources/j2cs/output.txt >> diff_out.txt

I have to add above command in the existing bat file to find the file size of diff_out.txt.

like image 691
Saurabh Ghorpade Avatar asked Jan 22 '26 05:01

Saurabh Ghorpade


2 Answers

You don't need an extra batch file, you could move your filename into %1 with a call to a function or you can use a FOR loop.

call :getFilesize diff_out.txt
echo %fileSize%
exit /b

:getFilesize
set filesize=%~z1
exit /b

Or

for %%A in (diff_out.txt) do set fileSize=%%~zA
like image 83
jeb Avatar answered Jan 24 '26 23:01

jeb


another variant:

@echo off

set file=c:\bookmarks.html

%1 %0 :: %file%
set len=%~z2
echo %len% 

pause

or with wmic:

D:\>set wql="drive='g:' and filename='function2' and extension='txt'"

D:\>wmic path cim_datafile where %wql% get name,filesize
FileSize  Name
621       g:\function2.txt

D:\>

or:

set file=G:\function2.txt

echo set len=%%~z1 >_tmp.bat
call _tmp.bat %file% && del _tmp.bat
echo %len%
like image 28
walid2mi Avatar answered Jan 24 '26 21:01

walid2mi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!