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...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
)
)

It's moving every file because your script is telling it too with this:
move C:\CoreFTPOutgoing\*.txt C:\CoreFTPOutgoing\archive\Try this:
@echo off
Rem Echo Filename & Size
cls
for %%a in ('dir C:\CoreFTPOutgoing\*.txt') do (
if %%~za GTR 1 (
move %%a C:\CoreFTPOutgoing\archive\
echo %%a %%~za
)
)I'm also baffled how your script works, because your not enclosing the parsed command in your FOR set in single quotes, but it still works.
"Computer security." — Oxymoron
Simple! He's envoking the orginal use of FOR. He's running the loop once for dir, and once for every C:\CoreFTPOutgoing\*.txt My version (untested):
@ECHO OFF
PUSHD C:\CoreFTPOutgoing
FOR %%a IN (*.txt) DO IF %%~Za NEQ 0 MOVE "%%a" archive
POPD
What do you mean by the original use of FOR? "Computer security." — Oxymoron
H:\scripts>for /?
Runs a specified command for each file in a set of files.FOR %variable IN (set) DO command [command-parameters]
%variable Specifies a single letter replaceable parameter.
(set) Specifies a set of one or more files. Wildcards may be used.
command Specifies the command to carry out for each file.
command-parameters
Specifies parameters or switches for the specified command.
Rofl. C:\toolbox>for /?
...snipped
FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]
...snippedMaybe I should have asked, when do you know you should use single quotes and when they are not necessary?
"Computer security." — Oxymoron
Look for the /F?
