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>
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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dustin SaundersCo-Founder and Chief ArchitectCommented:
Something along these lines should do what you need, just modified the source, destination, basename values.  Note that the {0} is in place where the date will be appended. (Powershell):
$directory = "C:\source\"
$destination = "C:\destination\"
$basename = "StaticFileName{0}.txt"
$todaysfilename = $basename -f $((Get-Date).ToString('MM-dd-yyyy'))

Copy-Item -Path $($directory + $todaysfilename) -Destination $destination

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bill PrewIT / Software Engineering ConsultantCommented:
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

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

eagle3344Author Commented:
Thank you to both. i appreciate you showing me how to accomplish that in a couple of different ways.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.