• Rename file with current date/time

    From benmorris293@gmail.com@21:1/5 to Jolly polly on Tue May 5 03:39:13 2020
    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)
  • From Juma Reimon@21:1/5 to All on Wed Jul 27 08:00:54 2022
    El viernes, 7 de agosto de 2015 a las 14:02:34 UTC-5, Jürgen Exner escribió:
    On Fri, 7 Aug 2015 11:45:21 -0700 (PDT), navan...@gmail.com wrote in microsoft.public.windows.powershell:
    On Thursday, September 10, 2009 at 10:20:21 AM UTC-5, Emo wrote:
    Oh, it took you only 6 years to check the command?
    $datetime = get-date -f MMddyy-hhmmtt (using tt for am or pm)

    the above command is not working
    "is not working" is a very useless problem description.

    This command is working perfectly fine with me.
    It assigns the current date/time to $datetime.

    What did you expect it to do?
    And what did you observe it doing instead?
    Just saying "is not working" without providing those 2 critical details
    is pointless.

    jue

    Que bueno que alguien tuvo la duda hace 6 años :)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)