If you have more than one file with the same date and time use this code: Get-ChildItem | ForEach{ $number = 1 $folderpath = $_.DirectoryName $DateTaken = $_.LastWriteTime.ToString("yyyy-MM-dd HH.mm") $newpath = $folderpath + "\" + $DateTaken + "_" + $number + $_.Extension while ((Test-Path -Path $newpath) -eq $true) {$newpath = Join-Path $folderpath($DateTaken + "_" + $number + $_.Extension) $number+=1} Rename-Item $_.pspath -NewName $newpath}
Coming from coding on DOS before Windows, I never even knew that Windows PowerShell existed, and so it was very useful to find your video to rename a bunch of files to their modified date. Thanks so much for sharing this.
You are an absolute hero! I have like 4 thousand photos that my iphone insists in export like a mishmash of letters and symbols, this is exactly what I was looking for, thank you!
MAKE A BACKUP BEFORE YOU MESS WITH THIS!!! Completely screwed myself trying this. Renamed all of my folders in a directory and could not get them back. Total nightmare!!! I'm so bummed.
Wow this was so helpful, right near the end i was like I need to put a name at the front how do i do that? Then you just go to explain it perfect tutorial!!!!!! saved me so much time!
To anyone asking "What if I have multiple of the same photo modified at the same time and date?" ie including the same seconds: Use the "Holiday" example at the end of Karina's video to append another value to the subset of files that became the duplicate timestamp. First temporarily put those files in a folder of their own and run the PowerShell/Terminal again. For me to match how my phone names these files, it involved adding "(O)" instead of "-Holiday". Then copy all the renamed files to your desired folder.
WOW! Thanks Karina for this awesome tool for renaming muliple files. Great to use to change the names of trailcam videos to a readable time line while viewing.👍
I use VLC Scene filter. This works great to rename the sequential files. Now I can stop VLC, Rename files, and re-start VLC and not worry about earlier files being overwritten.
Thanks for the great video. You saved me so much time - There was a time where I renamed my files manually, lol. I wish I had found this video earlier. Thanks so much!
Hi Karina I have the following problem: Some of my photos have the same date and time AND they don't have the 'date taken' value, therefore your code from the other video doesn't work. Is there a way to change the code so it only takes into account 'LastWriteTime' and not 'DateTaken'?
I have another video showing a different method for doing this that you could try. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-UKvkPnbQqwI.html This would be the code for if you have multiple files with the same date and time. $shell = New-Object -ComObject shell.application $ukCulture = [Globalization.CultureInfo]'en-GB' Get-ChildItem | ForEach{ $folderpath = $_.DirectoryName $folder = $shell.NameSpace($_.DirectoryName) $RawDate = ($folder.GetDetailsOf($folder.ParseName($_.Name),12) -Replace "[^\w /:]") $datetime = [DateTime]::Parse($RawDate,$ukCulture) $DateTaken = $datetime.ToString("yyyy-MM-dd HH.mm ") $number = 1 $newpath = $folderpath + "\" + $DateTaken + "_" + $number + ".jpg" If(Test-Path -Path $newpath){ while ((Test-Path -Path $newpath) -eq $true) {$newpath = Join-Path $folderpath ($DateTaken + "_" + $number + $_.Extension) $number+=1} Rename-Item $_.pspath -NewName $newpath} else {Rename-Item $_.pspath -NewName $newpath} }
Hi did you figure this out yet? I just had the same situation and found this to work. If you want to use the same method in this video you could also do the following (the method Karina mentions in her reply here is more intimidating to me!): Use the "Holiday" example at the end of Karina's video to append another value to the subset of files that became the duplicate timestamp. First temporarily put those files in a folder of their own and run the PowerShell/Terminal again. For me to match how my phone names these files, it involved adding "(O)" instead of "-Holiday". Then copy all the renamed files to your desired folder.
Hi did you figure this out yet? I just had the same situation and found this to work. Use the "Holiday" example at the end of Karina's video to append another value to the subset of files that became the duplicate timestamp. First temporarily put those files in a folder of their own and run the PowerShell/Terminal again. For me to match how my phone names these files, it involved adding "(O)" instead of "-Holiday". Then copy all the renamed files to your desired folder.
@@karinaadcock Im not a programmer but used your scripting it s very useful and u r a good teacher :) but as i faced exactly same problem than Vi Di Logs, i tested ur solution which give me Exception lors de l'appel de «Parse» avec «2» argument(s): «La chaîne n'a pas été reconnue en tant que DateTime valide. » Au caractère Ligne:5 : 1 + $datetime = [DateTime]::Parse($RawDate,$ukCulture) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : FormatException
@@martinlamotte3912 As your error is in French I'm guessing you are in France. So in the second line you should change [Globalization.CultureInfo]'en-GB' to [Globalization.CultureInfo]'fr-FR' I think the date format might be the same in France and England so you are getting an error but its still working.
Thank you sooooo much for this. I have one question: What's the command for renaming by date/time modified but keeping the original name on the end? Is that possible? I'm currently using Get-ChildItem | Rename-Item -NewName {$_.LastWriteTime.ToString("yyyy-MM-dd HH.mm.ss") + ($_.Extension)} and it's been working great. I'd just like to keep the original file number as well.
If you want to keep the original file name then you need: $_.basename Combined with everything else: Get-ChildItem | Rename-Item -NewName {$_.LastWriteTime.ToString("yyyy-MM-dd HH.mm") + $_.basename + $_.Extension} You probably also what a space or something separating the name and the date so: Get-ChildItem | Rename-Item -NewName {$_.LastWriteTime.ToString("yyyy-MM-dd HH.mm") + " " + $_.basename + $_.Extension}
This code should add the length to the end of the file name: $shell = New-Object -ComObject shell.application Get-ChildItem | ForEach{ $folder = $shell.NameSpace($_.DirectoryName) $length = ($folder.GetDetailsOf($folder.ParseName($_.Name),27) -Replace ":", ".") Rename-Item $_.FullName ($_.Basename + " - " + $length + $_.Extension)} I made another video about dates in powershell which explains some of this code: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-UKvkPnbQqwI.html
Hello Karina Thanks for your great RU-vid Chanel. Since a long time I rename 5 times a Week 14 Screenshoots per day (14 * 5 * 50 = 3500 a year) Now I'm looking for a solution to rename "Screenshot_20220504-160252.png" to "Screenshot_2022-05-04-16-02-52.png" The "_" already exists in the name. I didn't found any usefull staff to change these names. Do you have any solution? Thanks
This code should work. In the substring the first number is the index i.e. position of the number and the second number is the length i.e. the number of digits you want to include. Get-ChildItem | Rename-Item -NewName { $_.Name.Substring(0,15) + '-' + $_.Name.Substring(15,2) + '-' + $_.Name.Substring(17,5) + '-' + $_.Name.Substring(22,2) + '-' + $_.Name.Substring(24)}
@@karinaadcock Hello Karina Thanks for your answer. I tried it and it works. It seems like, that this code treatens the file name as a text and not as a date. So I googled all the time with the wrong parameters (Change date format) Thanks once again. Gella