Reading another file's size as a variable

Microsoft Windows xp professional editio...
October 27, 2009 at 14:49:01
Specs: Windows XP
I need my batch file to do something (or not) based on the size of another file.

I have a file called c:\myfile.txt and I need a batch file that will read myfile.txt's file size into a variable. I tried doing a dir c:\myfile.txt > text.txt and then reading in that text file but I don't know how to get the filesize only into a variable. Anybody?????


See More: Reading another files size as a variable

Report •


#1
October 27, 2009 at 19:48:49
This might do what you want:

@echo off
cls

for /f %%1 in ('dir/b myfile.txt') do (
    set filesize=%%~z1
)

echo %filesize%


Report •

#2
October 28, 2009 at 01:00:32
The process can be simplified further(avoiding the "dir" process):

for %%a in ("c:\myfile.txt") do (
    set filesize=%%~za
)


Batch Variable how to


Report •

#3
October 28, 2009 at 01:43:28
Hi Judago,

nice n smooth


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions


Ask Question