Page 1 of 1
Copy files with dynamic names
Posted: 13 Jan 2015 10:04
by mwatsondhs
I need to automate the following process:
A Crystal report is run on a monthly basis which creates the following file each month:
sls316_2015-01-06-04-12-37.pdf where 2015-01-06-04-23-37 is the date-time the pdf file was created.
Each month the date time changes and I need a batch script to copy this file to another directory.
Can I automate this with a .bat file?
Thanks.
Mark
Re: Copy files with dynamic names
Posted: 13 Jan 2015 10:18
by Squashman
Well this could be approached a couple of different ways but really need more information.
1) Are you just trying to synchronize two folders for backup purposes. The PDF should exist in both folders.
or
2) Will this be the only PDF in the folder that needs to be copied and then it is deleted from that original location?
or
3) Does the file name always start with sls316?
Re: Copy files with dynamic names
Posted: 13 Jan 2015 13:41
by mwatsondhs
Just copying .pdf files from a report server to a shared network drive. The timestamp is written into the file name and
only need to copy the latest dated file. There will be several files that need to be copied like this but if you could show me an
example for 1 I could do the others.
Re: Copy files with dynamic names
Posted: 13 Jan 2015 14:29
by Squashman
Could you please answer question 3.
Re: Copy files with dynamic names
Posted: 13 Jan 2015 14:38
by Squashman
If you want the newest PDF file in the directory you can do this.
Code: Select all
FOR /F "delims=" %%G in ('dir *.pdf /a-d /b /od') do set "newest=%%~G"
copy "%newest%" "X:\path to some folder\"
Re: Copy files with dynamic names
Posted: 13 Jan 2015 15:12
by mwatsondhs
Squashman,
Thank You very much, that worked perfectly.
Mark