Find file size and choose the smaller one.

August 11, 2011 at 08:06:28
Specs: Windows Server 2003
I am trying to grab a couple of files and compare the files by file-size and choose the smaller of the files.

I have the location of the files. The filename is very inconsistent ie. 001742.c3. But the file extension ends in "c3" I need to take, which may be multiple *.c3 files and compare them and then grab the smaller of the file to be FTP'd to another location.


See More: Find file size and choose the smaller one.

Report •

#1
August 11, 2011 at 09:09:00
for /f "delims=" %%a in ('dir *.c3 /o-s /a-d /b') do set smallest=%%a

How To Ask Questions The Smart Way


Report •

#2
August 24, 2011 at 07:18:15
If i wanted the larger one just change setting to "larger"? would that be correct?

Report •

#3
August 24, 2011 at 07:41:52
"Smallest" is just a name I chose. It could have easily been "BigBob’sBoisterousBarbequeBash." It's not because that'd be too much typing.

If you wanted the largest:

for /f "delims=" %%a in ('dir *.c3 /os /a-d /b') do set BigBob’sBoisterousBarbequeBash=%%a

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
August 24, 2011 at 07:57:57
i tried this, but its not working. it doesn't show that smallest filename.
0017231.c3 should be the smaller file

Set _File1=%1
Set _File2=%2
for /f "delims=" %%a in ('dir *.c3 /o-s /a-d /b') do set smallest=%%a
If %smallest%==1 (Set smallest=%_File1%) Else (Set smallest=%_File2%)
Echo The smallest file is %smallest%

Output:
C:\1500Billing>Set _File1=

C:\1500Billing>Set _File2=

C:\1500Billing>for /F "delims=" %a in ('dir *.c3 /o-s /a-d /b') do set smallest=
%a

C:\1500Billing>set smallest=00017230.c3

C:\1500Billing>set smallest=00017231.c3

C:\1500Billing>If 00017231.c3 == 1 (Set smallest= ) Else (Set smallest= )

C:\1500Billing>Echo The smallest file is
The smallest file is


Report •

#5
August 24, 2011 at 08:23:17
Take your program, and read it out, in English. Like so:
C:\1500Billing>If 00017231.c3 == 1 (Set smallest= ) Else (Set smallest= )
If %smallest% (currently "00017231.c3") is "1", set %smallest% to nothing, otherwise set %smallest% to nothing.
Echo The smallest file is %smallest%
Show the value of %smallest% (Guaranteed to be nothing.)

How To Ask Questions The Smart Way


Report •

#6
August 24, 2011 at 11:42:52
Ok i see my problem.

thank you, very much


Report •

Ask Question