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 •

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

@echo off

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

echo %filesize%

Report •

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 •

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

nice n smooth

Helping others achieve escape felicity


Report •

Related Solutions

Ask Question