I am trying to loop through files in a directory, and execute actions based on the file size. Files are typically larger than 2 GB. I am using DisableDelayedException to handle exclamation marks in file names correctly. The relevant part of the bigger batch looks as follows:
for %%x in (*.ts *.mpg *.mp4 *.wmv) do (
If Not "%RamDisk%" == "" (
Set "Filesize=%%~zx"
Call :GetFilesizeMB
If %FilesizeMB% lss 7000 (
Echo Working from RAMDisk, copying %%x with %%~zx Bytes to RAMDisk... >>"%Logfile%"
Copy "%%x" %RamDisk%\
%RamDisk%
Cd \
) Else (
Echo %%x is too big - %%~zx Bytes -, not working from RAMDisk. >>"%Logfile%"
)
)
:GetFilesizeMB
Set "FilesizeMB=%Filesize:~,-6%"
Goto :EOF
Problem is: I cannot get the "if lss" part to work: If I work with if %%~zx directly, I get an error, because the file size too big for 32 bit. So I'm trying to approximate MBs by cutting off the last 6 figures. FilesizeMB is set correctly in :GetFilesizeMB, but after returning into the for loop, FilesizeMB is empty again.
How can I execute actions on a file depending on its file size in a for loop?