I have 14,000 pictures sorted into files by year and month but taken with multiple cameras and I want the file name to reflect the date taken. For example October 16, 1998 pictures are in a folder called 1998\10 October\19981016.
I want the all the pictures to be named 19981016_0001 19981016_0002 etc. I tried multiple suggestions but it hasn't worked.
I can get to the point where it lists the folder I want to change but I'm unable to actually change it. All of my pictures are .jpg.
Attempts
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 parentheses for example vacation (1).jpg. I want a four digit counter after an underscore at the end of my date, e.g. 19981016_0001
Open File Explorer, go to a file folder, select View > Details, select all files, select Home > Rename, enter a file name, and press Enter. In Windows PowerShell, go to a file folder, enter dir | rename-item -NewName {$_.name -replace “My”,”Our”} and press Enter.
To batch rename files, just select all the files you want to rename, press F2 (alternatively, right-click and select rename), then enter the name you want on the first file. Press Enter to change the names for all other selected files.
The syntax is way off. A few issues:
$($.19981016)
was intended to produce, but $( ) evaluates the expression in the parentheses and interpolates the result into the string, and you're getting the error because $.19981016
is not a valid expression. The error would be repeated for each .jpg file in the directory.{0:00000000#}
in a formatted string will create a zero-padded number of 9 digits, but a shorter way to do that is {0:D9}
. However, I thought you wanted the zero-padded number to have 4 digits, so that should be {0:0000#}
or {0:D4}
.Foreach {$i=1} { [...]
is supposed to do. The keyword foreach can mean a foreach loop, or it can be shorthand for Foreach-Object. In this context, receiving input from a pipeline, it's necessarily the latter, but this syntax is incorrect either way.This will do what you want, if I understand the description correctly:
$i = 1
Get-ChildItem *.jpg | %{Rename-Item $_ -NewName ('19981016_{0:D4}.jpg' -f $i++)}
The filenames will be 19981016_0001.jpg, 19981016_0002.jpg, 19981016_0003.jpg, etc.
A few notes:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With