On Wednesday, 18 December 2013 23:24:43 UTC, Jolly polly wrote:
<> wrote in message
Emo於 2009年9月10日星期四UTC+8下午11時20分21秒寫道:
I hope this is simple :)
I'm looking to rename a file in C:\folder\dailybackup.bak to C:\folder \MMddyy-hhmm.bak
I just need to do it for one file. The original filename with always
be "dailybackup.bak"
I understand how to use get-date and how to format it as in:
$datetime = get-date -f MMddyy-hhmmtt (using tt for am or pm)
And I understand how to do a simple file rename using ren. In rename,
it asks for the path and then NewName...but I can't figure out how to
get the info from $datetime into the filename.
so...how can I rename the file using the info from $datetime?
I'm pretty new to powershell so any help is greatly appreciated :)
try this
Rename-Item C:\foldername "$((get-date).toString('foldername_dd-MM-yyyy'))"
Hi all, I see there was a bit of an argument above. I couldn't get either of the suggestions to work for a file, maybe they have changed the powershell commands since. The above suggestion left me with a .AxA file so I've tweaked it for anyone else
googling the answer. The following works well from CMD (so can be made into a batch script):
Powershell Rename-Item C:\filename.txt "filename_$((get-date).toString('dd-MM-yyyy')).txt"
This will give you C:\filename_05-05-2020.txt if it was ran today.
Best of luck!
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)