Link to home
Start Free TrialLog in
Avatar of eagle3344
eagle3344

asked on

Copy file based upon changing file name

Hello experts,

i am in need of a script that can copy a file on a daily basis from one directory to another based upon a changing filename. The filename's base stays the same, however the current date is appended to the end of the file.

For Example:
StaticFileName<Today's date in MM-DD-YYYY format>
or
StaticFileName12-17-2018    <-----This is the filename that needs to be copied on 12-17-2018

I am not a scripting expert so suggestion on best method (powershell, batch etc) is also appreciated.

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of Dustin Saunders
Dustin Saunders
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 Bill Prew
Bill Prew

And here is a small BAT script approach in case that's useful...  You didn't specify if there was an extension on the file name, so I didn't add one, but add it in if needed.

@echo off
setlocal

set DateStamp=
for /f "tokens=* skip=1" %%A in ('wmic os get LocalDateTime') do (
    if not defined DateStamp set DateStamp=%%A
)
set DateStamp=%DateStamp:~4,2%-%DateStamp:~6,2%-%DateStamp:~0,4%

copy "C:\FromDir\StaticFileName%DateStamp%" "C:\ToDir\StaticFileName%DateStamp%"

Open in new window


»bp
Avatar of eagle3344

ASKER

Thank you to both. i appreciate you showing me how to accomplish that in a couple of different ways.