How to rename photos to the date taken

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ส.ค. 2024
  • $shell = New-Object -ComObject shell.application
    $ukCulture = [Globalization.CultureInfo]'en-GB'
    Get-ChildItem | ForEach{
    $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")
    Rename-Item $_.FullName ($DateTaken + $_.Extension)}
    Find out what the code is for your country: docs.microsoft...

ความคิดเห็น • 92

  • @karinaadcock
    @karinaadcock  2 ปีที่แล้ว +22

    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} }

    • @daxteoh27
      @daxteoh27 2 ปีที่แล้ว

      Thank you Karina, you saved so much of my time!

    • @maxwang2537
      @maxwang2537 2 ปีที่แล้ว

      This is great!

    • @maeganfitzgerald7097
      @maeganfitzgerald7097 2 ปีที่แล้ว

      Hi Karina, thank you so much for this great tutorial! I am using the code provided in the pinned comment for the multiple files with the same date and time. It works well overall except that for most, if not all, of the files that get renamed, it skips a number at the end. For example, if I have 12 files with the same date and time, it gives the correct suffix for the first 11 (e.g. "_1", "_2"..."_10" and "_11") and then assigns "_13" to the final file even though it should be "_12". Any idea as to why this is happening? Thank you for any additional assistance! - Maegan

    • @LaBnErD85
      @LaBnErD85 ปีที่แล้ว +1

      Thank you so much for this briliant solution and excellent video. Can we extend the date to include seconds i.e. HH.mm.ss?

    • @madeleinejones8
      @madeleinejones8 ปีที่แล้ว

      Hi I want to do this formula but for Date Modified as per the other YT video. But the other video just links to this videa when there are multiple files with the same date and time for Date Modified. (I can't do Date Taken as it's mostly missing/incorrect.)

  • @wellzi2546
    @wellzi2546 2 ปีที่แล้ว +67

    Gives answer in first 30 seconds, offers the rest of the video for those interested in knowing what it means to learn. THIS is how ALL videos should be structured. Thank you. :)

    • @andrewtregoning
      @andrewtregoning ปีที่แล้ว

      literally. this is unironically one of the best instructional videos on the internet. and I've watched 1000s!!!

  • @RonClabo
    @RonClabo ปีที่แล้ว +1

    I really appreciate your video. This is a solution to a problem I've been wanting to solve -- renaming my camera photos to include the date taken. There are shareware apps to do this but they only do my jpg files, not the associated raw files. Your approach works great. Doing it via PowerShell is very cool. And the way you provide a detailed bottoms-up explanation is absolutely fantastic. You explain this so well. THANK YOU.

  • @ttran8205
    @ttran8205 ปีที่แล้ว +3

    Exception calling "Parse" with "2" argument(s): "String was not recognized as a valid DateTime."
    Doesn't work

    • @Ana-fj9dt
      @Ana-fj9dt ปีที่แล้ว +1

      Same: Exception calling "Parse" with "2" argument(s): "String was not recognized as a valid DateTime."

  • @wuivy4597
    @wuivy4597 5 หลายเดือนก่อน

    Love it so much with answer at the very beginning followed by detailed explanation. Then user could adjust according to their own situation!

  • @richardpeppiette7821
    @richardpeppiette7821 2 ปีที่แล้ว +1

    Brilliant piece of work. Love your clarity of thinking and presentation

  • @koalanof
    @koalanof 2 ปีที่แล้ว

    I actually love you so much for the super fast, straight to the point explanation!

  • @JosepeLupi
    @JosepeLupi ปีที่แล้ว +5

    Great video! Thank you for sharing it. If there are photos taken at the exact same date, hour and minute, the code will produce an error. To avoid this issue, you can check if the new file name already exists and add a number after the file name. One way to modify the code to achieve this would be:
    $shell = New-Object -ComObject shell.application
    $ukCulture = [Globalization.CultureInfo]'en-GB'
    Get-ChildItem | ForEach-Object {
    $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")
    $NewName = $DateTaken + $_.Extension
    # Check if the file name already exists
    if (Test-Path ($_.DirectoryName + '\' + $NewName)) {
    $counter = 1
    $NewNameBase = $DateTaken + "_$counter" + $_.Extension
    while (Test-Path ($_.DirectoryName + '\' + $NewNameBase)) {
    $counter++
    $NewNameBase = $DateTaken + "_$counter" + $_.Extension
    }
    $NewName = $NewNameBase
    }
    Rename-Item $_.FullName $NewName
    }

    • @shadowsvt
      @shadowsvt ปีที่แล้ว

      JL, I had an issue with Karina's coding as I have many photos taken at the same date and time. I tried your code and it did the same thing Karina's did. Changes them all to the same date even though some were taken on other dates. Any ideas ? Thanks!

  • @rexkirkland3720
    @rexkirkland3720 2 ปีที่แล้ว +1

    Thank you for making my family photo project easier. I have about 2 thousand photos that I want to put on a time line. :-)

  • @mihai-19
    @mihai-19 ปีที่แล้ว +4

    (This is a wonderfully explained tutorial; thank you)
    Why do all date-taken strings end in :00 (seconds)?

  • @machomachinmachinmachinmac6910
    @machomachinmachinmachinmac6910 3 ปีที่แล้ว +4

    Nice script.
    For the U.S, change the second line to be en-US instead of en-GB
    The problem with this script occurs when you have several photos that were taken within the same minute.
    The script will change the first one it encounters and leaves the other ones alone.

    • @Grauniadangel
      @Grauniadangel 3 ปีที่แล้ว

      Hi, yes that's exactly my issue as I mentioned above.

    • @karinaadcock
      @karinaadcock  3 ปีที่แล้ว +1

      This will add a number on the end of the file names which will count up by one each time. The number won't restart with each date, it will just keep counting up for every file in the folder.
      $shell = New-Object -ComObject shell.application
      $ukCulture = [Globalization.CultureInfo]'en-GB'
      $number = 1
      Get-ChildItem | ForEach{
      $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")
      Rename-Item $_.FullName ($DateTaken + "_{0:0000}$($_.Extension)" -f $number++)}

    • @machomachinmachinmachinmac6910
      @machomachinmachinmachinmac6910 3 ปีที่แล้ว

      @@karinaadcock : I just tried it. WORKS GREAT! Thanks.

  • @lbx15970
    @lbx15970 ปีที่แล้ว +3

    Thank you this is so helpful! However, in my case, some of the photos do not have the parameter of date taken, and an error occurs. How can I fix this? I prefer not renaming these photos that do not have date taken information.🤔

  • @ricovalera8069
    @ricovalera8069 ปีที่แล้ว +2

    Karina, Thank you for these videos. I have used the "LastWriteTime" code and it worked perfectly. I have some files that I need to use the Date Taken as you explain on this video.
    I get and error message for some of the files that have the same TIME. I believe it's because it's not considering the seconds (although the seconds are diferent and showing on windows)
    Do you know why it's not renaming the file using the seconds, but only HH and mm?

  • @RobertBachrach
    @RobertBachrach 2 หลายเดือนก่อน

    Thank so much for the clear instructions and script. It worked well for me. I found your video after Magic File Renamer was not properly working for all the files I had in a folder.
    Unfortunately downloading from Google Photos or Apple iCloud does not keep the file date as date taken.

  • @antoniopereira2575
    @antoniopereira2575 6 หลายเดือนก่อน

    Thank you so much!!! And thank you for providing the solution in the very beginning of the video!

  • @brevinpalmes3742
    @brevinpalmes3742 3 ปีที่แล้ว +1

    Thank you so much for this.
    it solved so many problems for me

  • @TruthWielders
    @TruthWielders 2 ปีที่แล้ว

    When I look at my folders in file explorer there is a column named "Date", which is different then any of the other dates found in the details, that's not the time & date listed from DIR command (same "LastWriteTime" from "get-childitem"). The one in file explorer could be the date created on the system and stored at low level in directory entry, that's the one useful for me ! I can't find a way to get to it though ? Yes, i checked all the individual labeled as some date from the list generated by "0..287|Foreach-Object {'{0} = {1}' -f $_, $shellfolder.GetDetailsOf($null,$_) }"
    And many thanks, solid and instructive piece of work !

    • @ricovalera8069
      @ricovalera8069 ปีที่แล้ว

      Hello Pierre, did you find a solution for this issue? I'm having the same problem when the "date taken" is not accurate on windows. Otherwise, I use the other code given by Karina, when "LastWriteTime" is good. If you can share the solution, it'd be greatly appreciated

  • @alanstephens3966
    @alanstephens3966 ปีที่แล้ว +2

    Question - Is it possible to retain the original file name and append the date taken onto it?
    Example: convert 'IMG_3650.jpg' to 'IMG_3650 2023-01-02 17.52.jpg'
    Or, better yet, convert to: '2023-01-02 17.52 IMG_3650.jpg'
    One final question - is it possible to have the time show with colon - '17:52' instead of '17.52'?
    Excellent video - thank you!

    • @alanstephens3966
      @alanstephens3966 ปีที่แล้ว +2

      Figured out how to keep original name:
      Rename-Item $_.FullName ($DateTaken + " " + $_.BaseName + $_.Extension)}
      Can't figure out how to keep the colon in the time format HH:mm...

  • @jeremychick619
    @jeremychick619 5 หลายเดือนก่อน

    Excellent explanation. Thank you.

  • @zacharyhall2304
    @zacharyhall2304 2 ปีที่แล้ว +2

    Thank you so much for this. I have lots of pictures that are missing a Date Taken attribute. Is there a way to add an IF statement so that if the Date Taken attribute is missing it'll use the file date?

  • @ChrisRobertsAtLarge
    @ChrisRobertsAtLarge 3 หลายเดือนก่อน

    well done, and thank you!

  • @vladimir416
    @vladimir416 ปีที่แล้ว

    Thanks, this helped me a lot :)

  • @sohaib-ashraf
    @sohaib-ashraf 2 ปีที่แล้ว

    This is amazing. Thank you so much!

  • @TTtipsforlife
    @TTtipsforlife 7 หลายเดือนก่อน

    Hi Karina, thanks for your video and worked like a treat. i have a mix of Videos and Pictures in my folder. is there a way of adding the File type into the name as well so when i look at my images in Large preview mode i will know if its a video or a pic?

  • @erfanzarenia2579
    @erfanzarenia2579 2 ปีที่แล้ว

    Thank you so much for such helpful video! I have one question:
    I don't use Georgian calendar, but after "Get-ChildItem" command in PowerShell the "LastWriteTime" is in Georgian calendar.😓 Is it possible to change photos name in any other Windows supported calendars using this method? It'll be a great help🥺

  • @dominiktakac5468
    @dominiktakac5468 ปีที่แล้ว

    Thank you, Thank You and Thank you!

  • @ItsukaIshida
    @ItsukaIshida ปีที่แล้ว

    Thank you lots for this!

  • @LiiiiiiiiiiP
    @LiiiiiiiiiiP ปีที่แล้ว

    Hi Karina, thanks for the very informative video. I am a non-IT guy and have no knowledge nor skills in script writing. I follow every step but my computer showed errors right from the start. Is there a limit to the version of windows I am operating in? For your advice, please.

  • @brittneespindler881
    @brittneespindler881 ปีที่แล้ว +1

    Can you please tell the code to add multiple files with the same date and time 'modified date' as a file name instead of the 'created date'

  • @Science3D
    @Science3D 3 ปีที่แล้ว

    great video, thanks

  • @citadino4970
    @citadino4970 2 ปีที่แล้ว

    Hi Karina! I am glad I found this tutorial. I am not an expertt at all with PowerShell, but wanted to give it a try. Hope you can help me tyring to figure out an error I am getting with the Parse method as it is not working due to an error in the date being passed (RawDate is not recognized). I am wokring with en-CA and my dates are YYYY-MM-dd nut when getting the date it removes the dashes (-) and then converting to $datetime does not work.
    This is what I am getting back in the $RawDatre variable: 20041215 12:16 PM
    Error is: Exception calling "Parse" with "2" argument(s): "String '20041215 12:16 PM' was not recognized as a valid DateTime."
    InvalidOperation:

    • @karinaadcock
      @karinaadcock  2 ปีที่แล้ว

      Try adding dashes to the things you don't want to replace -Replace "[^\w /:-]"

  • @Grauniadangel
    @Grauniadangel 3 ปีที่แล้ว

    Karina, i've found this extremely helpful so thanks very much.
    The only lasting issue i have is that when i run the script some files return an error as they are part of a 'burst' of pictures taken. I tried to add seconds to the time which i hoped would solve the problem but it just returns zero's. Is there a quick add-on to the above that might an extra +1, +2 or +3 etc to differentiate the files perhaps? I am using your script and doing this manually at the moment but would love to be fully automated.

    • @karinaadcock
      @karinaadcock  3 ปีที่แล้ว +4

      This will add a number on the end of the file names which will count up by one each time. The number won't restart with each date, it will just keep counting up for every file in the folder.
      $shell = New-Object -ComObject shell.application
      $ukCulture = [Globalization.CultureInfo]'en-GB'
      $number = 1
      Get-ChildItem | ForEach{
      $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")
      Rename-Item $_.FullName ($DateTaken + "_{0:0000}$($_.Extension)" -f $number++)}

    • @Grauniadangel
      @Grauniadangel 3 ปีที่แล้ว

      @@karinaadcock Thanks Karina.

  • @colecormier2797
    @colecormier2797 ปีที่แล้ว

    I live in Canada and when I paste the script it says "The string is missing the terminator: '."

  • @DjAdriano83
    @DjAdriano83 3 ปีที่แล้ว

    Awesome help!
    How would be the code for renaming videos to the media created?

    • @scottdriiver
      @scottdriiver 3 ปีที่แล้ว

      i believe its just changing the line $RawDate line to the following.
      $RawDate = ($folder.GetDetailsOf($folder.ParseName($_.Name),4) -Replace "[^\w /:]")

  • @vikstar22
    @vikstar22 ปีที่แล้ว

    Hi there - thanks for this but I really needed this code for audio files, and it doesn't appear to work. Does it only work on photos?

  • @KayossPlays
    @KayossPlays ปีที่แล้ว

    Might there be a code to change all 'date created' to 'date taken' on multiple files with all different dates?

  • @318harshit
    @318harshit 2 หลายเดือนก่อน

    not working in may 2024

  • @akyhne
    @akyhne ปีที่แล้ว

    Doesn't work for me. It renames the first file to just ".jpg", then call an error on the rest, as the name is already in use.

    • @akyhne
      @akyhne ปีที่แล้ว

      There's an issue with your code. I ran some of the code, that you created during the video.
      Already at..
      $folder = (Get-ChildItem | Select-Object -Index 0).DirectoryName
      $shell = New-Object -ComObject shell.application
      $shellfolder = $shell.NameSpace($folder)
      $shellfolder.GetType()
      .. I got an error. After fiddling a bit around, it turns out, your code example doesn't like, that there's a sub-folder in the folder with the images.
      i get this error for all files:
      Exception calling "Parse" with "2" argument(s): "Strengen blev ikke genkendt som en gyldig DateTime."
      At line:4 char:1
      + $datetime = [DateTime]::Parse($RawDate,$ukCulture)
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : FormatException
      You cannot call a method on a null-valued expression.
      At line:5 char:1
      + $DateTaken = $datetime.ToString("yyyy-MM-dd HH.mm")
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : InvokeMethodOnNull
      The "Strengen blev ikke genkendt som en gyldig DateTime" part, translates to "The string was not recognized, as a valid DateTime". I'm not sure, if it's because my PC runs Date and time, as dd-mm-yyyy (da-DK), and not the "English/American" version, with mm-dd-yyyy.

    • @akyhne
      @akyhne ปีที่แล้ว

      So my problem is here:
      $RawDate = ($folder.GetDetailsOf($folder.ParseName($_.Name),12) -Replace "[^\w /:]")
      Your output of $RawDate is in this format: "11/04/2018 19:46".
      Mine is like this: "11042018 19:46" (no slashes).
      That's why your code doesn't work for me.

    • @akyhne
      @akyhne ปีที่แล้ว

      Further development.
      I found out, that I could do...
      $RawDate = ($folder.GetDetailsOf($folder.ParseName($_.Name),12) -Replace "[^\w /: /-]")
      $datetime = [DateTime]($RawDate)
      $datetime = [DateTime]::Parse($RawDate,$ukculture)
      $datetime}
      ... and that gives me output like "21. februar 2018 15:16:00" for $datetime.
      Problem is, I still get an error "Cannot convert value "21-02-2018 15:16" to type "System.DateTime".

  • @dominiktakac5468
    @dominiktakac5468 ปีที่แล้ว

    Is possible to make code that rename into date taken but with seconds? It would be very helpful. Thank you.

  • @doretsion3593
    @doretsion3593 2 ปีที่แล้ว

    why Video file change to JPG? without media created date

  • @stevenkruger8329
    @stevenkruger8329 2 ปีที่แล้ว

    how could I add an other line of code, like after this script has renamed the file, is should for backup reasons copy the newnamed files into a new folder. Does anybody know? Its an amazing Video/Explanation Karina!!! Thanks a million!!

    • @karinaadcock
      @karinaadcock  2 ปีที่แล้ว +1

      xcopy "source folder" "destination folder" will copy all files from one folder to another, for example,
      xcopy "C:\Users\Karina Adcock\Desktop\photos" "C:\Users\Karina Adcock\Desktop\backup"
      If the backup folder hasn't been created yet it will ask you if its a file or directory. Then you put D for directory and it will make the folder and copy the files to it.

  • @morganalabeille5004
    @morganalabeille5004 ปีที่แล้ว

    Any way to do this with a batch file?

  • @brianaalexis4203
    @brianaalexis4203 2 ปีที่แล้ว

    Do you by any chance know how to do this for a mac?

  • @lauskuba
    @lauskuba ปีที่แล้ว

    Hello! this been very useful, I used for a lot even well explained for a complete unkown of powershell with zero experience coding I understood a lot. I have a question for anybody can help with an extension.
    I have many photos without date of capture. I would like then when there is no info for capture date, take the minimum date between Date, Creation Date and Modify Date.
    By trying different numbers in GetDetailsOf () I found creation date is "4", modifyDate is "3" and I am stil missing regular Date access and the skills to evaluate the minimum of them in the lack of Capture Date "12" and rewrite the original names with the resulting ones.
    Thanks for reading so far and I appreciate this video and anybody giving a help with this.

    • @lauskuba
      @lauskuba ปีที่แล้ว

      Atm I manage to improve selecting only desire format files with Where:
      Get-ChildItem | Where{$_.Extension -like ".jpg" -or $_.Extension -like ".jpeg" -or $_.Extension -like ".gif" -or $_.Extension -like ".png" -or $_.Extension -like ".mp4" -or $_.Extension -like ".mov"} | ForEach{
      But still there is a problem with files with no capture datetime information, they get name replaced with datetimes of other files (which are nonrelated and wrong)

  • @baraclude
    @baraclude 3 ปีที่แล้ว

    How do you do the same with Videos if I want to use "Media Created" date? I played around with the RawDate and wasn't able to make it work.

    • @scottdriiver
      @scottdriiver 3 ปีที่แล้ว

      i believe its just changing the line $RawDate line to the following.
      $RawDate = ($folder.GetDetailsOf($folder.ParseName($_.Name),4) -Replace "[^\w /:]")

    • @doretsion3593
      @doretsion3593 2 ปีที่แล้ว

      @@scottdriiver it is not working for video, how i change to media created?

    • @scottdriiver
      @scottdriiver 2 ปีที่แล้ว

      @@doretsion3593 you need to change part of the script to what I mentioned above. (Testing my brain as it was 7 months ago since I posted this comment 😂)

    • @doretsion3593
      @doretsion3593 2 ปีที่แล้ว

      @@scottdriiver i tried it with limited success, some file success and some not, also I have 1 folder with pictures and movies - how can i do it for both at 1 time?

  • @amberwiebe658
    @amberwiebe658 2 ปีที่แล้ว

    Hello there, I've tried editing the code to be used in Canada, but I keep getting errors. What would I have to change to have it work here? Thank you!

    • @AlexanderGuevaraLopez
      @AlexanderGuevaraLopez 2 ปีที่แล้ว

      Same here! Can't get it to work. $datetime throws an error

    • @tapeton
      @tapeton 2 ปีที่แล้ว +2

      I'm in Canada as well and was also getting errors. I had to follow the tutorial in full to find out, but it seems it was because the date in my Windows is separated with - instead of / like Karina shows in her video.
      This means I had to write "[^\w -:]" instead of "[^\w /:]" since my dates didn't have any slashes.
      I know it's been months since your question but hope that helps anyone popping by!

    • @dlinkdj
      @dlinkdj ปีที่แล้ว +1

      @@tapeton Thanks a lot saved me so much time

    • @marcounicio
      @marcounicio ปีที่แล้ว +1

      @@tapeton Thanks a lot!!!

  • @victoriaroome9299
    @victoriaroome9299 2 ปีที่แล้ว

    Hi Katrina, thank you for posting this! I have tried to alter the code for my situation but it comes up with errors. Can you please help? I changed UK to AU throughout; and wanted to change from "Date Taken" (I have no data for these files) to "Date Modified" so I updated the text and changed the attribute from 12 to 3. It shows lots of errors though :D

    • @karinaadcock
      @karinaadcock  2 ปีที่แล้ว +1

      Have you tried using this method th-cam.com/video/v82gkPYZa7Y/w-d-xo.html

    • @victoriaroome9299
      @victoriaroome9299 2 ปีที่แล้ว

      @@karinaadcock thank you for your response, I have been able to resolve for my situation. Thank you again for your clear and informative style! Simply wonderful. I am most grateful and will pass your videos along to others.