1.

Solve : Help in an XCOPY script?

Answer»

I am running this code in a batch file every 2 minutes to copy from one server to another.  I need to copy specific files to a DESTINATION.  The script works fine, but the problem is that it copies over and over the ones it already did.  Is there a way to copy the files Im loking for, but exclude any that have all ready been copied?  The destination folder is a folder that another program "looks" in constantly.  when files land in this folder, the program takes them and then deletes them because they were processed.  My script copies the files again, and of course the program reprocesses them because it doesnt know they were done earlier in the day.  The source folder will have PDF's and XML's added all day long as patients are seen by the physician.  I hope this makes sense.  Here is what code I have, but i need it to only copy new files from the source:

for /f "tokens=1-5 delims=/ " %%d in ("%date%") do cd s:\02\%%f
s:
for /D %%F in (*) do xcopy %%F\*.pdf \\MHCInterface\Heartlab /C /Y
for /D %%F in (*) do xcopy %%F\*.xml \\MHCInterface\Heartlab /C /Y
del \\MHCInterface\Heartlab\*.red.*

Thanks for any help you can offerI think Robocopy may be a better option for you.well the OS is winxp and server 2000.  Maybe I could do something with the archive bit in the xcopy script?  like turn off the archive if I copy it and have the script only copy new files with the bit set?  once copied undo the archive?Robocopy can monitor the source for changes so that is why I suggested that.

If you don't want to use robocopy the I think your other solution would be to make a log file of all the files that were copied. 

Instead of using the whacky way you were using the For /d option with two loops you could just use the for /f loop with the dir command and pipe it to the findstr command and use the inverse match option and the G option to use the log as the match. Basically telling findstr to find all files that you haven't copied yet.this sounds exactly what I need, but I have no clue how to even begin it.  Could you help me with the basics?  The structure is like this:

c:\Heartlab\1  <---for January
c:\Heartlab\1\01  <--- January 1st
c:\Heartlab\1\02\  <--- January 2nd
c:\Heartlab\1\03  <--- January 3rd....etc

then in each day there is a folder for each patient.  It is a random number to represent a new patient, so it could look like this:


c:\Heartlab\998821  <----patient #1
c:\Heartlab\1\015981  <----patient #2
c:\Heartlab\1\02\53721  <----patient #3
c:\Heartlab\1\03\54321  <----patient #4

In each patient folder is three files.  blah.xml  blah.pdf and blah.red.xml.  I only need the pdf and xml file copied (not the .red.xml) tp the servers listening folder \\mhcinterface\HeartlabI am confused as to why you would make the Month a single digit number and the day a two digit number.  Why aren't you leading with a Zero on both?sorry...i wrote that wrong...month and day are single digits.  not sure why I typed it that way. Quote from: mikedela on February 19, 2012, 06:10:31 PM

sorry...i wrote that wrong...month and day are single digits.  not sure why I typed it that way.
Just wondering because your original script shows a 02 for the month.
So when you echo the date variable from the command prompt and lets say it is Thursday February 9th, 2012 does it output like this
Thu 2/9/2012
Going to assume so because you are using a FOR Loop to PARSE the date apart.  I prefer to use the leading zeros in my Regional Settings.  Makes it easy to use the DATE variable in script with string parsing.  Plus if you are using the date to name files it makes it real easy to sort the file name by the date when it is 20120208_Myfile.doc.

Going to assume you screwed up this example as well.
Quote
c:\Heartlab\998821  <----patient #1
c:\Heartlab\1\015981  <----patient #2
c:\Heartlab\1\02\53721  <----patient #3
c:\Heartlab\1\03\54321  <----patient #4
I would assume that a patient should never be directly in the source directory or in a months directory. It should always be in the day directory of the month.ys your riht again.  I have so much on my plate, I confuse myself.  So all patients for the day go into that days folder.  for the feb 10th, they would go into 2\10\xxxx1, then next patient would 2\10\xxxx2 etc.  My script right now works perfect as it takes the day and copies every pdf and xml from the subfolders to the destination, then deletes the xxxxx.red.xml.  Its just that the script doesnt know if it copied the files already or not.  I dont know how to pipe into a file and then read it to see if its been copied.  Can you show me an easy example of a script that copies c:\mike\*.pdf to d:\Mike but only copies files it HASNT copied before?  The destination folder will not delete any txt documents, so we could parse into a txt and read from that.  I appreciate your help.  I have cracked my head on the wall with this one....im so frustrated and I know its so easy.I'm getting in on this thread, late in the game, so to SPEAK, but here's what I do.

In case of a hard drive crash or Windows boot failure, I don't want to loose any of my files from "My Documents" (MS Office) or "My Files" (Word Perfect) so I wrote a batch file, using XCOPY to copy only new or changed files to my assigned storage area on a separate hard drive.

With XCOPY you have a long list of switches that can be applied.
One switch, /M   copies a file and turns off the Archive bit so that file is NOT copied again, unless it's changed, which will reset the archive bit.

Even though I have several thousand files in my source directories, only a very few files get copied on each run of the batch file, keeping my backup time to just a few seconds.   Here is a SAMPLE line from my backup batch file:

xcopy "C:\Documents and Settings\Alexi\My Documents\*.*" "D:\My Documents\" /s /y /H /R /M

I've printed out the entire list of XCOPY switches and I suggest that anyone wanting to use this command, do likewise.

If you run this command from a Command Prompt, you will get the switch list as a text file in your root directory, then you can pull it up in Notepad and print it out.

XCOPY /? > C:\xcopy.txt

I always prefer to use what MS gave us for free in every version of Windows, instead of installing more and more software.
Adding more and more programs every time you want to do something can CREATE a real 'Quagmire'.

XCOPY is just one DOS program that can save you a lot of time and effort once you learn how to use it.

I can send a batch file, using XCOPY to anyone in the world, who used any version of Windows and be assured it will run as intended.  Witness the batch files I've placed for download on my own web site.


Good Luck,
the Shadow B)
Good idea Shadow.  That will work perfectly.

Just so you know Robocopy is native to Vista and Windows 7.  XP just required that you download and install the Windows 2003 resource kit to use it.

Mike, make sure you use Xcopy's other option EXCLUDE so that you don't copy the .RED.XML file as well.


Discussion

No Comment Found