Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6192557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:57:47+00:00 2026-05-24T02:57:47+00:00

I’m in need a script, in PowerShell or batch script, that will do the

  • 0

I’m in need a script, in PowerShell or batch script, that will do the following.

  1. Rename a file to append creation date minus 1 day to the filename.

    For example:

    foo.xlsx (created 7/27/2011)

    foo-2011-07-26.xlsx –note, it’s yesterday’s date.

    Date format isn’t too important as long as it’s there. There will be 10 files (all with the same creation date), so either I can copy and paste the same renaming line for the different files (just rename the filename) or just have the script affect all *.xlsx files in the existing folder.

  2. Create a new folder where those files are and name it ‘fooFolder-2011-07-26’ (yesterday’s date).

  3. Move those renamed files to that folder.

I only have limited experience with PowerShell. It’s on my todo list of languages to learn..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:57:48+00:00Added an answer on May 24, 2026 at 2:57 am

    Here you go. It could be shortened up a lot using aliases and piping and whatnot, but since you’re unfamiliar with Powershell still, I decided to write in a more procedural style for your reading:

    function MoveFilesAndRenameWithDate([string]$folderPrefix, [string]$filePattern) {
      $files = Get-ChildItem .\* -include $filePattern
      ForEach ($file in $files) {
        $yesterDate = $file.CreationTime.AddDays(-1).ToString('yyyy-MM-dd')
        $newSubFolderName = '{0}-{1}' -f $folderPrefix,$yesterDate
        if (!(Test-Path $newSubFolderName)) {
          mkdir $newSubFolderName
        }
        $newFileName = '{0}-{1}{2}' -f $file.BaseName,$yesterDate,$file.Extension
        Move-Item $file (Join-Path $newSubFolderName $newFileName)
      }
    }
    

    You would paste the above into your Powershell session (place it in your profile). Then you call the function like this:

    MoveFilesAndRenameWithDate 'fooFolder' '*.xslx'
    

    I tend to use more aliases and piping than the above function. The first version I wrote was this, and then I separated parts of it to make it more comprehensible to a Powershell newcomer:

    function MoveFilesAndRenameWithDate([string]$folderPrefix, [string]$filePattern) {
      gci .\* -include $filePattern |
        % { $date = $_.CreationTime.AddDays(-1).ToString('yyyy-MM-dd')
            mkdir "$folderPrefix-$date" 2>$null
            mv $_ (join-path $newSubFolderName ('{0}-{1}{2}' -f $_.BaseName,$date,$_.Extension))}
    }
    

    Edit: Modified both functions to create dated folder for the files that match that date. I considered making a temporary directory and grabbing a single date from the files moved to it, finally renaming the directory after the loop. However, if a day should be missed and files for 2 (or more) days get processed together, there would still be a folder for each day with these, which is more consistent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.