1.

Solve : File Size - It's Crunch Time?

Answer»

Folks, I have to be ABLE to determine whether the file created as a result of an FTP is greater than zero bytes. I'm no DOS wiz and I've looked over and tested a mountain of code - none of it seems to work under NT.

Ultimately what needs to happen is that any zero byte file created as a result of the FTP process will be deleted. I can and will use a fixed file name in this case. I'm sure many of you out there have run into and solved this problem before.....

Since this original posting, I've found a solution that seems to work......

for /f "tokens=3" %%a in ('dir myfile.txt ^| find "/"') do set size=%%a
if %size% EQU 0 DO SOMETHING

However, I don't understand WHY it works, nor if it's doing what I originally intended. Can someone explain to me exactly what this snippet really does?If you run a DIR list manually, you should be able to verify whether or not the batch file works correctly. Unless a NT DIR list is different from what is usually generated, I'm guessing your batch file does not work.

This may work a bit better:

Code: [Select]for /f "tokens=4" %%a in ('dir /a:-d ^| find /i "myfile.txt"') do set size=%%a
if %size% EQU 0 DO SOMETHING

Explaining how a FOR statement works can be a bit tricky. Either use FOR /? at your COMMAND prompt, or use Google.

Happy Coding. 8-)Thanks Sidewinder - I'll certainly give it a go this morning! I found with the previous code that it would always return zero since the file being tapped by the 'Find' is encrypted......

I DO appreciate your help and I'll post later after I get done fooling with it......Sidewinder - I had to tweak the code to use token 3 instead of 4, but after that it worked like a charm!

Thanks Again. LOOKS like this issue is a done DEAL!



Discussion

No Comment Found