Renaming 400 files in a folder based on creation date Help RRS feed

  • General discussion

  • I am New to Powershell, and the comandlets I have found are helpful to a point. I have had success with partial renaming using the following script:

    dir | rename-item -newname {$_.name -replace "Old Mailing", "Company Name"}

    With the result of having all my files successfully renamed to "Company Name Blah Blah Blah"

    My problem is I do not know enough about Powershell to get a little more complicated with the naming.  My Ultimate Goal is for all Files to have the Following Naming convention:

    All Files are PDF and currently all files in a folder are for the same dept.

    <Company Name> <YYYYMMDD created> <static department code>

    Example: ABC KING 20180405A 1149.pdf

    I am willing to do some research if I can get pointed in the right direction.  I just do not understand how to string all the changes together, and how to include an optional modifier for files created on the same date.  

    I also found a comandlet about setting the name to the create date, but I cannot refind it and did not write it down. Nor do I understand if it is possible to have a static start and end, but Variable middle part of the name. 

    Open to running three seperate renaming scripts, but I do not know how I would go about Adding "Company Name" to front after all creation dates are set, then one to add the "department numbers" at the End.

    Is what I want to do even possible?

    Thursday, April 5, 2018 5:55 PM

All replies

  • https://ss64.com/ps/

    dir -> pull creation date -> pull company name -> assign department code -> format date -> rename company name date dep code -> reiterate 

    Thursday, April 5, 2018 6:03 PM
  • Start by going through a basic tutorial on PowerShell.  You cannot guess your way through this.

    Learn PowerShell  


    Thursday, April 5, 2018 6:22 PM
  • Start by going through a basic tutorial on PowerShell.  You cannot guess your way through this.

    Learn PowerShell  


    i beg to differ jrv, i've seen people guess their way to the top of the corporate ladder.
    • Edited by The Grim Thursday, April 5, 2018 6:28 PM
    Thursday, April 5, 2018 6:27 PM
  • I guess that explains why so many corporations go bankrupt.


    Thursday, April 5, 2018 6:36 PM
  • explains away the weekly data breaches. reported or not.
    Thursday, April 5, 2018 6:38 PM
  • explains away the weekly data breaches. reported or not.

    For more than 30 years I have watched the damage done by techs and tech managers who learn by guessing.  Most of our security failures can be traced to technical incompetence.  Now that the breaches are viral we may get stuck with some very difficult new laws.  New Jersey has already proposed licensing techs and programmers.   ost larger companies are now testing all new techs.  If you can't pass a test on basic computing and os/software then no job.  In my last big company we tested everyone with a two hour test.  No interview if you failed the first hour test.  Second hour was specific to the position; tech support, help desk, programmer, dba.


    Thursday, April 5, 2018 6:51 PM
  • now if we could just get CEO's and CFO's to do the same for a CIO/CTO position; along with all sub positions as you have mentioned we would be in business.

    then you just have to worry about those test answers finding there way into the general populous such as many of the current certification tests. food for thought.

    Now @GameCat318, any progress on your script?

    Thursday, April 5, 2018 7:01 PM
  • Ok but, with me, you have to pass my test which consists of about 5 challenging tasks that a trained user could accomplish in 15 to 20 minutes.  The tasks are never the same twice.

    On programmer had a brilliant resume but scored low on the tests.  The exec said we should hire him anyway and let him learn the rest.  I gave my test which proved he didn't really understand the material.  He passed due to cramming and a test that was not really well targeted.

    At other times applicants that scored low were able to pass my tests and the discussion we had concerning the exact requirements showed me they knew the material but likely had issues with tests.

    You have to be flexible but a test score of 50 or lower will generally not get you a job.


    Thursday, April 5, 2018 7:43 PM
  • This thread needs to get split to a discussion about 8 post ago.

    Bill?  How about "The value of formal PowerShell training?"


    Thursday, April 5, 2018 7:45 PM
  • Not Yet, Got dragged in to an hour long death by power point with telcon for a bonus 15 minutes of sir, can you please mute your phone, yes, Sir you... no, not hold, will you please take us off hold and stop the hold music... SIR, I can hear you laughing...

    And the can you throw together an excel report comparing quartly manning reports and customers served over the last 4 years. 

    I will look at the basic tutorial and then see if it the suggestions make more sense.  I will check back when I find something or as often as possible to see more suggestions.

    Thursday, April 5, 2018 8:12 PM
  • I can feel the pain in every keystroke GameCat, stay stronk.
    Thursday, April 5, 2018 8:38 PM
  • So from the first three courses, it would appear, I will be using the pipeline feature to set up my renaming script.  I plan to listen, and learn to the rest of the MVA on powershell this weekend and next week, I will post my results when I find them.  Thank you for pointing me in a good direction with end result of more understanding and tools, and not just the answer, that I blindly follow.
    Friday, April 6, 2018 10:58 PM
  • MVA video courses are free and usually very entertaining.  There are a few dozen short videos on special aspects of PowerShell and dotNet which are worth watching when you get settled in.


    Friday, April 6, 2018 11:07 PM