Click here for important information about

robocopy batch file

December 15, 2009 at 17:51:39
Specs: Windows XP
i want to write a robocopy batch file to only copy files that have change since the last copy and then to zip them to a folder
im a robocopy novice can someone please help

See More: robocopy batch file

December 16, 2009 at 07:36:46
That question is very difficult actually. When you say to only copy files that have changed, since a given date, THAT on itself is easy ... but of course, he would ADD these file to the reference backup structure he already has ... making it a full - updated - backup structure.

What I think you want, is to have a resulting structure of files, but ONLY the ones that have changed after a given date. Correct ?

The issue is the reference, if you update to an existing structure, he uses the files of the already existing files on the target structure, as reference. But since you do not want those files ... you don't have a reference.

What you can do, is run XCOPY with /D, and supply it with a date. Example :

/D:m-d-y Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time.

XCOPY /D:1-1-2010

He would then only copy the files from source structure, which are newer than that date, and you can copy to a non-existant target structure. Maybe this is what you are looking for. Of course, YOU need to provide that date !

And note, and this is very tricky, there IS a difference between a file with a change-date later than 2010, and a file which has been "changed" after 2010. Example, on the 5th of January, I can copy a file with a timestamp of 1997, onto a file that was previously created on the 3rd of january of 2010.

The file has got a very old date, but still, it has changed. The date of actual change, is not always the date of the timestamp of the file itself.

Report •

January 14, 2010 at 08:21:20

> i want to write a robocopy batch file to only
> copy files that have change since the last copy
> and then to zip them to a folder
> im a robocopy novice can someone please help
> thanks

Here is a script that may, possibly, help.

# Script Zip.txt
# Go to directory where files are.
cd "/path/to/folder"

var str lasttime, list, file

# Get the previous zipping time.
# We store it in file C:/lasttime.txt.
cat "C:/lasttime.txt" > $lasttime
# Immediately save current time
# to "C:/lasttime.txt".
echo gettime() > "C:/lasttime.txt"
# First time when we run this script,
# $lasttime will be empty. That's ok.
# This logic accounts for that.

# Collect a list of files that were MODIFIED since
# $lasttime.
lf -r -n "*" "." (($ftype == "f") AND ($fmtime >= $lasttime)) > $list

# Add files to zip one by one.
while ($list <> "")
    # Get the next file.
    lex "1" $list > $file

    # Add this $file to zip.
    echo -e "DEBUG: Adding file " $file " to zip."
    # Add the system command here that will add
    # the file to the zip file.


I am not sure what zip software you are using. Figure out the exact commands to start, add and end the zip. Then call those commands from the above script by prepending "system " to it.

Script is in biterscripting ( ). Change "/path/to/folder" to the correct path where these files are. Copy and paste the script into a file, say, "C:/Scripts/Zip.txt", enter the following command in biterscripting.

script "C:/Scripts/Zip.txt"

The script can also be scheduled in the task scheduler to run periodically with the following command syntax.

"C:/biterScripting/biterScripting.exe" "C:/Scripts/Zip.txt"

Report •

January 16, 2010 at 04:44:23
That's unix coding, Sen.

Robocopy is a Windows tool ;)

Report •

Related Solutions

January 17, 2010 at 16:41:35
Hi tvc: How you doing of late ?

You are right - that looks like UNIX coding - but it works on Windows as well. I am certain that biterscripting code works on windows - I am using it on Windows Vista at this very moment.

I like robocopy. I think it's great. My code is merely complementary to Robocopy.

Report •

January 23, 2010 at 06:35:57
Well, the opening post is very unclear ("zip them to a folder") so it would be interesting to get what is asked first, then see how, but I cannot imagine that using unix code on windows would be simplier ... he may be just needing a Windows batch file with 1 line of code, containing a call to Robocpy with the correct parameters ...

Report •

January 23, 2010 at 13:04:56
@johnhawks: did you ever get it working?

Report •

Ask Question