Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have this simple batch script which copies the newest file in some dir to another place. I want this script to also ignore all files (in the DIR command section) under 1GB of size.

FOR /F "delims=|" %%I IN ('DIR "Y:\DEVL\*.*" /B /A-D') DO SET NewestFile=%%I 

copy "Y:\DEVL\%NewestFile%" "F:\DEVL\%NewestFile%"

Any help would be very appreciated.

share|improve this question

1 Answer 1

Option 1: If you want to copy the newest file, but only if it's greater than 1GB, just replace your copy command with:

robocopy "Y:\DEVL" "F:\DEVL\" "%NewestFile%" /min:1073741824

/min:n defines the minimum size in bytes.

Option 2: If you want to copy the newest file of all files that are greater than 1GB, it's more complicated.

@echo off

Set CopyResult=0
FOR /F "delims=|" %%I IN ('DIR "Y:\DEVL\*.*" /B /O:-d /T:w /A-D') DO Call :DoCopy "%%I"
Goto :EOF

:DoCopy
  IF %CopyResult%==1 Goto :EOF
  set CurrentFile=%1
  robocopy "Y:\DEVL" "F:\DEVL" %CurrentFile% /njs /njh /is /min:107374182
  Set CopyResult=%errorlevel%

/min:n defines the minimum size in bytes.

share|improve this answer
    
That will only skip the copying if the file is less than 1gb. It will not, as I think the OP wants, copy the newest file that IS less than 1gb. –  Glenn Sullivan Feb 27 '13 at 15:13
    
Glenn: Thanks, I guess you can read the question two ways. I updated my answer. –  ZEDA-NL Feb 28 '13 at 11:32
    
ERROR : Invalid Parameter #3 : " /min:1073741824" And it took the wrong file :) The script now runs over all files, taking the actually newest (after listing all files as newest one after the other) - a 70kb file. –  Yoffe Mar 4 '13 at 6:33
    
Hi Zeda, Again I'm not receiving any successful results here. Please try and run your script and see what happens –  Yoffe Mar 18 '13 at 9:37
    
About the error. If you remove @ECHO OFF command you'll see the actual cammand that is executed. Can you copy that in a comment for me? –  ZEDA-NL Mar 18 '13 at 15:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.