I'm new to making Batch files and ran into a problem. My plan is to compare the size (in byte) of a file (unknown file name but with a fixed extension) with a few 'maxfilesizes' and do different stuff depending on the size of the file.
@echo off for /F %%a in ('dir /b *.bin') do set file=%%~na :BEGIN for %%X in (%file%.bin) do if %%~zX LSS 1500000000 goto 15MB for %%X in (%file%.bin) do if %%~zX LSS 5000000000 goto 50MB for %%X in (%file%.bin) do if %%~zX LSS 10000000000 goto 100MB for %%X in (%file%.bin) do if %%~zX LSS 15000000000 goto 150MB goto Error :15MB echo Less than 1500000000b. Do stuff here.. 15MB. goto TheEnd :50MB echo Less than 5000000000b. Do stuff here.. 50MB. goto TheEnd :100MB echo Less than 10000000000b. Do stuff here.. 100MB. goto TheEnd :150MB echo Less than 15000000000b. Do stuff here.. 150MB. goto TheEnd :Error echo File size greater than 14GB. Aborting.. :TheEnd echo All done. pause I have tested this batch with a file that is ~8.000.000.000 bytes so ':100MB' should be triggered, but it is not. Instead I always get 'File size greater than 14GB. Aborting..' Please keep in mind that I'm a beginner, so the above batch is probably not the most efficient one.. Any help would be much appreciated.
EDIT: @Aacini thank you so much, I've just tested your code with some of my files and it does exactly what I wanted it to do.
[...] but I think you should review the numbers you use in the bytes -> MB conversion...
These are no conversions. I only use them for the goto's because if filesize less than 1500000000 bytes, I want the file to be split into 15MB parts (echos will be replaced by commands). Hence the -> goto 15MB. Hope that clears it up. Thanks again!