Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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?????

This might do what you want:
@echo off cls for /f %%1 in ('dir/b myfile.txt') do ( set filesize=%%~z1 ) echo %filesize%

The process can be simplified further(avoiding the "dir" process):
for %%a in ("c:\myfile.txt") do ( set filesize=%%~za )

Hi Judago,
nice n smooth
=====================================
Helping others achieve escape felicityM2

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |