• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

Enhancement to my .bat file?

I opened this question below for help 'getting' the most recent file written to a given directory.  
http://www.experts-exchange.com/Operating_Systems/MSDOS/Q_21402564.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



0
RLLewis
Asked:
RLLewis
  • 5
  • 5
1 Solution
 
pcsentinelCommented:
I think you meant to post this into the MSDOS area
0
 
RLLewisAuthor Commented:
yes, but how do i change that?
0
 
SteveGTRCommented:
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
RLLewisAuthor Commented:
But what is the d/ option?
0
 
SteveGTRCommented:
Here's what the xcopy /? help says:

/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.
0
 
RLLewisAuthor Commented:
let me give it a shot, steve.  i will let you know
0
 
RLLewisAuthor Commented:
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?
0
 
SteveGTRCommented:
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.
0
 
RLLewisAuthor Commented:
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?
0
 
SteveGTRCommented:
That's what the /d option is suppose to do. Give it a try.
0
 
SteveGTRCommented:
I believe my solution works.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now