Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 14,000 picture sorted into files by year and month but taken with multiple cameras. I want the file name to reflect the date the photo was taken.

For example, all pictures taken on October 16, 1998 are in a folder called 1998\10 October\19981016.

I want the all the pictures to be named 19981016_0001 19981016_0002 etc.

I can get to the point where it list the folder I want to change but I'm unable to actually change it. All of my pictures are .jpg.

I created a temp file of copies in case I messed it up. I started by typing:

cd "C:\Documents and Settings\Brooke LastName\Desktop\Temp" 

then after successfully getting my file to load I used a formula I found on this forum.

ls *jpg | Foreach {$i=1} {Rename-Item _ -NewName ("$($.19981016){0:00000000#} .jpg" -f $i++) -whatif}

The error I got said

Unexpected token ' .19981016' in expression or statement.

At line:1 char:12 + $.19981016 <<<<

The error repeated several times

I found several formulas on the web but most created files that would number with parenthesis for example vacation (1).jpg I want a four digit counter after an underscore at the end of my date. ie 19981016_0001

share|improve this question

I think you modified formula, and made at least two mistakes:

  • Rename-Item $_ -> otherwise PowerShell will attempt to rename file named "_"
  • "$($_.Directory.Name)_{0:D9}.jpg" -f $i++ - you need to grab directory name of current object, and for formatting - it's easier to use D# format, easier to count how many digits you get in the end...
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .