0

Would like to automate in a batch file the copying of a set of text files we receive monthly in a new folder on a network drive to another network drive, automatically replacing any existing files there.

Some background: we receive the second week of each month an extract of data files, 14 in total, in a folder labeled with this naming convention, DatabaseFilesyyyymmdd, on one of our shared drives (\\server1\receptacle). After receipt, another team validates the data, and afterwards informs our team they are ready for loading into an existing Oracle table. We copy the files (not the folder) to another network drive (\\server2\loading) and kick off the script.

Naturally, that new folder is titled with the same date of the extracted data files. Creating a .bat file we then could launch to automate the copying chore is the goal, but the variability of the new folder names has me stumped in scripting this. Any help appreciated.

Edit: perhaps a way to discover and script the name of the most recently created folder in \receptable is what I'm attempting to figure out in copying the files to another drive.

  • 1
    copy F:\receptacle\* F:\loading? – G-Man Sep 14 '17 at 20:12
  • If the files were at the root of F:\receptacle that would work, but the new files will be situated in different subfolders each month. – le0pard13 Sep 14 '17 at 20:15
  • So what’s the problem? Writing a batch file to generate the DatabaseFilesyyyymmdd folder name? edit your question to say where you’re stuck. – G-Man Sep 14 '17 at 20:22
  • Yes, that's where I'm stuck. For instance, the most recent folder we received was "DatabaseFiles20170912". Next month it's likely on the 10th, but sometimes they're delayed a day or so, and always with the date of the extraction. Perhaps, I should be looking for the folder with the most recent creation date? – le0pard13 Sep 14 '17 at 20:38
  • I’m sorry; did you miss the part where I said ‘‘edit your question…’’? – G-Man Sep 14 '17 at 20:44
0

This sounds like you want some level of manual control so your team can check it first.

Make both the batch file and kick-off script take the name of the folder as a (command-line) parameter, and then call the batch file with the folder name which it can use for copying and then pass that to the kick-off script.

You can make a custom "Send-to" target for the explorer context menu so you just pick and click.

If you need a watched-folder situation, make a new folder for the 1st team to drop the files into called "validated" and have your batch file ensure that the validated folder only ever has the one job in it. Maybe with a "canary file" type setup so that the job won't kick off while the files are being transferred in.

If you need to mirror the "receptacle" folder in "loading," use robocopy to avoid unneeded recopying.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.