Jump to content

Windows Copy Script


Recommended Posts

Hello Good peeps of Mother Earth,

Can someone help me with a Windows scripts please?

I need a script that will:

1. Check a directory for new files

2. Copy ONLY new files to another location

3. Repeat the process

I can do this in UNIX with the -newer command, but I'm unfamiliar with a way to do this in Windows. Does anyone have a script on hand that can do this? I looked at RoboCopy and RichCopy for Windows, but they don't have the flexibilty I'm looking for.

I tried using the below commands and it works ... except .... I have another system doing an FTP to get the copied files. Once the system copies the files using ftp, it renames and moves the files. Because of this, when the xcopy command runs again, it recopies all the files. I don't want this.

set backupcmd=c:windowssystem32xcopy.exe /c /d /e /h /r /y

set dt=%date:~10,4%%date:~4,2%%date:~7,2%

%backupcmd% source_dir *%dt%.txt destination_dir

Link to comment
Share on other sites


What I'm trying to do is:

1. Check a directory for all files

2. copy all files with *.tada extensions

3. modify a file "afterme.txt"

When the script runs again it should:

1. Check a directory for all files newer than "afterme.txt"

2. Copy all new files with the *.tada extension

3. modify the "afterme.txt" file

I can do this in unix with the following command "find / -type f -name "*.tada" -newer afterme.txt -exec cp {}......" But I don't know how to duplicate this in windows. Obviously the newer command doesn't exist in windows. XCOPY doesn't offer this kinda of flexibilty, I don't know VB or Perl, but I need something to accomplish this task in windows.

Link to comment
Share on other sites

What I'm trying to do is:

1. Check a directory for all files

2. copy all files with *.tada extensions

3. modify a file "afterme.txt"

When the script runs again it should:

1. Check a directory for all files newer than "afterme.txt"

2. Copy all new files with the *.tada extension

3. modify the "afterme.txt" file

I can do this in unix with the following command "find / -type f -name "*.tada" -newer afterme.txt -exec cp {}......" But I don't know how to duplicate this in windows. Obviously the newer command doesn't exist in windows. XCOPY doesn't offer this kinda of flexibilty, I don't know VB or Perl, but I need something to accomplish this task in windows.

Someone just reminded me of Cygwin. Since I can do what I need in UNIX, Cygwin is the answer!

Link to comment
Share on other sites

  • 1 month later...

The original poster wants to

1. Check a directory (assuming C:/dir1) for all files

2. copy all files with *.tada extensions (assuming to C:/dir2)

3. modify a file "afterme.txt" (assuming also in C:/dir2)

Here is a script in biterscripting (http://www.biterscripting.com/install.html) . Will work on all windows versions.

# Get the modification time stamp of file C:/dir2/afterme.txt.
var str timestamp; af "C:/dir2/afterme.txt"
if ($fexists)
set $timestamp = $fmtime;
endif
# If afterme.txt does not exist, then $timestamp will remain empty.

# Get a list of *.tada files in directory C:/dir1 which were modified after $timestamp.
var str filelist; lf -n "*.tada" "C:/dir1" ($fmtime >= $timestamp) > $filelist

# Copy files one by one.
while ($filelist <> "")
do
var str file; lex "1" $filelist > $file
system copy ("\""+$file+"\"") "C:/dir2"
done

# Modify the modification timestamp for the afterme.txt file.
echo > "C:/dir2/afterme.txt"

# We are done !

Sen

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...