1.

Solve : Batch file to move files if gtr 0?

Answer»

Hey, just stuck on a little something that I'm overlooking obviously. I'm using the following to check for files in a specified directory. If the size is greater than 0, I want to MOVE those that are greater than 0 to an archive folder.

As you can see, what it is doing is moveing every file to the archive not just those greater than zero size. So I'm obvioulsy missing something or incorrectly stated something...any thoughts?

@echo off
Rem Echo Filename & Size
cls
for %%a in (dir C:\CoreFTPOutgoing\*.txt) do (
if %%~za GTR 1 (
move C:\CoreFTPOutgoing\*.txt C:\CoreFTPOutgoing\archive\
echo %%a %%~za
)
)


What happens when you make your condition

if NOT %%~za==0 (

GrahamThanks for the reply Graham. Unfortunately, it still moves all the files regardless of size (or no size).

Here is the cmd file with the condition change:

@echo off
Rem Echo Filename & Size
cls
for %%a in (dir C:\CoreFTPOutgoing\*.txt) do (
if NOT %%~za==0 (
move C:\CoreFTPOutgoing\*.txt C:\CoreFTPOutgoing\archive\
echo %%a %%~za
)
)
Guess what? You kinda stuffed up...


move C:\CoreFTPOutgoing\*.txt C:\CoreFTPOutgoing\archive\
When this is executed, it moves every text file to /archive, not just the ones GTR 0.

What you probably want is this:
move C:\CoreFTPOutgoing\%%~nxa C:\CoreFTPOutgoing\archive\


If that doesn't work, just tell me. If it does, tell me anyway.

Thanks Dark Blade....that did the trick.

I knew it was MOVING everything because of that line, but I wasn't SURE what the correct syntax was since I don't WRITE these too often.

So YES, it is working properly now. Appreciate the replied from both of you.



Discussion

No Comment Found