Link to home
Start Free TrialLog in
Avatar of RLLewis
RLLewis

asked on

Enhancement to my .bat file?

I opened this question below for help 'getting' the most recent file written to a given directory.  
https://www.experts-exchange.com/questions/21402564/XCOPY-or-FORFILES.html
it works beautifully.  i have determined, though, that i may need to revise, such that i can retrieve mutliple files since the last time run.  for example, since the last time run, maybe for whatever reason the job hasn't run for 4 or 5 days, or more specifically, somebody has dropped several files in on the same day - all of which i need to retrieve.  so, the last time it's run, i've picked up filname.cax.20050505, but now I've got to go in there and get filname.cax.20050506, filname.cax.20050507, filname.cax.20050508 and filname.cax.20050509.  

so, yesterday in the dir i had these:

filname.cax.20050505
filname.dif.20050505
filname2.cax.20050505
filname2.dif.20050505

today, i've got these -- my most recent bat does fine to pick up filename.dif.20050509, but it fails to get the rest -- i need the 3 i don't have -- which are the last three:

filname.cax.20050505
filname.dif.20050505
filname2.cax.20050505
filname2.dif.20050505
filname.dif.20050509
filname2.cax.20050509
filname2.dif.20050509



Avatar of pcsentinel
pcsentinel

I think you meant to post this into the MSDOS area
Avatar of RLLewis

ASKER

yes, but how do i change that?
I was thinking and you might want to just use the /d option of the xcopy command to accomplish the task. I've modified the previous solution to include both the .cav. and .dif. files:

@echo off

for /f "delims=" %%a in ('dir /od /a-d /b "\\server1\bb\*.*" ^| findstr "\.cax\. \.dif\."') do xcopy "\\server1\bb\%%a" "\\server2\g$\mssql\tools" /d

Good Luck,
Steve
Avatar of RLLewis

ASKER

But what is the d/ option?
ASKER CERTIFIED SOLUTION
Avatar of SteveGTR
SteveGTR
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RLLewis

ASKER

let me give it a shot, steve.  i will let you know
Avatar of RLLewis

ASKER

Well, Steve, what do you think --- as far as I'm getting this /d, it's based on datetime of the file, so how would I specify a time that was right for all files and did not exclude some or cause the same file to be copied > 1?  Does that make sense?
If the files don't exist in the destination directory they will be copied. If they do exist only files new will be copied. The first time you ran the process you'll probably copy more files then you want, but from then on it will only copy over fresh files. As for copying files more that once, this should only happen if the files have been updated in the source directory. Then I'd think that you'd want the latest and greatest in the destination directory.
Avatar of RLLewis

ASKER

ok, steve, lets say in extract 1 i've got these files:

filname.cax.20050505  - 5pm
filname.dif.20050505  - 3pm
filname2.cax.20050505  - 5pm
filname2.dif.20050505   - 6pm

and in extract 2 i've got these:

filname.cax.20050505  - 5pm
filname.dif.20050505  - 3pm
filname2.cax.20050505  - 5pm
filname2.dif.20050505   - 6pm
filname2.cax.20050505  - 5:30pm
filname3.dif.20050505   - 6pm

in extract 1 i want everything.  in extract 2, i want only the new files - but note - i'd gotten one of those files before (filname2.cax.20050505), it's just an updated/newer version.

is this possible?
That's what the /d option is suppose to do. Give it a try.
I believe my solution works.