Openai/6910af03-f58c-800b-a67e-c1aff06d11d4


This conversation was exported from ChatGPT[1]

gpt-5 edit

User: Help me with an inline Powershell command to rename bunch of files, which has 'Snapchat-' in it while keeping the rest … edit

Help me with an inline Powershell command to rename bunch of files, which has 'Snapchat-' in it while keeping the rest as it is. I want the 'Snapchat-' to be replaced by 'IMG_' followed by the date in the YYYYMMDD format and then the rest as it is. You can take the date from the files metadata individually.

Assistant: Got it 👍 — you want a single-line PowerShell command that: edit

Got it 👍 — you want a single-line PowerShell command that:

  • Finds all files with "Snapchat-" in the name.
  • Extracts each file’s metadata date (from the Date column, not creation/modification date).
  • Renames the file so that "Snapchat-" becomes "IMG_<YYYYMMDD>_" while keeping the rest of the original name.

Here’s the exact inline PowerShell command you can run in the folder:

Get-ChildItem -File | Where-Object { $_.Name -like '''Snapchat-''' } | ForEach-Object {
    $date = (Get-ItemProperty $_.FullName -Name Date).Date.ToString('yyyyMMdd')
    $newName = $_.Name -replace 'Snapchat-', "IMG_$date<code>_"
    Rename-Item $_.FullName -NewName $newName
}
- Get-ChildItem -File — lists all files in the current directory. edit

Where-Object { $_.Name -like 'Snapchat-*' } — filters only the files that contain “Snapchat-”.

  • (Get-ItemProperty $_.FullName -Name Date) — reads the metadata “Date” column (the one visible in File Explorer, which reflects content date for photos/videos).
  • .ToString('yyyyMMdd') — formats that date to YYYYMMDD.
  • -replace 'Snapchat-', "IMG_$date"— replaces the “Snapchat-” prefix withIMG_YYYYMMDD.
  • Rename-Item — renames the file in place.
If you have: edit
Snapchat-12345.jpg   (Date: 2023-07-14)
Snapchat-98765.mp4   (Date: 2024-02-01)

After running:

IMG_20230714_12345.jpg
IMG_20240201_98765.mp4

Would you like it to also search through subfolders recursively? If yes, I’ll tweak it to handle that too.

gpt-5-t-mini edit

User: It's giving this error: edit

It's giving this error:

Get-ItemProperty : The property Date does not exist or was not found. At line:2 char:14 + $date = (Get-ItemProperty $_.FullName -Name Date).Date.ToString(' ... + 05:24, 10 November 2025 (UTC)05:24, 10 November 2025 (UTC)05:24, 10 November 2025 (UTC)05:24, 10 November 2025 (UTC)05:24, 10 November 2025 (UTC)05:24, 10 November 2025 (UTC)05:24, 10 November 2025 (UTC)Lukegao (talk) 05:24, 10 November 2025 (UTC)

   + CategoryInfo          : ReadError: (Date:String) [Get-ItemProperty], IOException
   + FullyQualifiedErrorId : GetValueError,Microsoft.PowerShell.Commands.GetItemPropertyCommand

You cannot call a method on a null-valued expression. At line:2 char:5 + $date = (Get-ItemProperty $_.FullName -Name Date).Date.ToString(' ... + 05:24, 10 November 2025 (UTC)05:24, 10 November 2025 (UTC)05:24, 10 November 2025 (UTC)05:24, 10 November 2025 (UTC)05:24, 10 November 2025 (UTC)05:24, 10 November 2025 (UTC)05:24, 10 November 2025 (UTC)05:24, 10 November 2025 (UTC)05:24, 10 November 2025 (UTC)05:24, 10 November 2025 (UTC)05:24, 10 November 2025 (UTC)05:24, 10 November 2025 (UTC)05:24, 10 November 2025 (UTC)

   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
   + FullyQualifiedErrorId : InvokeMethodOnNull

Does Powershell doesn't have the capability of reading metadata of photo files?

Assistant: Good question — PowerShell can read photo metadata, but Get-ItemProperty -Name Date is not the right way to read EXIF /… edit

Good question — PowerShell can read photo metadata, but Get-ItemProperty -Name Date is not the right way to read EXIF / shell metadata. The Date property you tried to read doesn't exist as a filesystem property, so Get-ItemProperty returned $null and you hit the null-method error.

Photos and videos store metadata in different places (EXIF tags for JPEGs, different shell properties for MP4/HEIC, etc.), so a robust approach tries a few common sources and falls back to a filesystem timestamp if metadata isn’t present.

Below is a robust inline PowerShell snippet you can run in the folder. It:

  • Finds files with Snapchat- in the name.
  • Attempts to read System.Photo.DateTaken (EXIF Date Taken) via the Shell COM ExtendedProperty.
  • Falls back to System.ItemDate/System.DateModified or the file LastWriteTime if needed.
  • Renames Snapchat- → IMG_<YYYYMMDD>_ keeping the rest of the filename.

Run this (you can paste it as a single block into PowerShell):

Get-ChildItem -File | Where-Object { $_.Name -like '''Snapchat-''' } | ForEach-Object {
    # try to get EXIF / shell metadata first, otherwise file timestamp
    $dt = $null
    try {
        $shell = New-Object -ComObject Shell.Application
        $folder = $shell.Namespace($_.DirectoryName)
        $item = $folder.ParseName($_.Name)
        # try common metadata properties
        $candidates = @(
            "System.Photo.DateTaken",
            "System.Media.DateEncoded",
            "System.ItemDate",
            "System.DateModified",
            "Date taken",
            "Date"
        )
        foreach ($prop in $candidates) {
            if (-not $dt) {
                $val = $null
                try { $val = $item.ExtendedProperty($prop) } catch {}
                if ($val -and $val -ne '') {
                    # Some values include time; attempt to parse
                    if ($val -is [datetime]) { $dt = $val } else {
                        try { $dt = [datetime]::Parse($val) } catch {}
                    }
                }
            }
        }
    } catch { $dt = $null }
    if (-not $dt) { $dt = $_.LastWriteTime }                # final fallback
    $datestr = $dt.ToString('yyyyMMdd')
    $newName = $_.Name -replace 'Snapchat-', "IMG_${datestr}_"
    Rename-Item -LiteralPath $_.FullName -NewName $newName
}

Notes & tips

  • This covers most JPGs/HEICs and many video formats, but some files may use different metadata fields (camera apps vary). In those rare cases the script will fall back to the file’s last write time.
  • If you want it to run recursively through subfolders, add -Recurse to Get-ChildItem.
  • If filenames can contain special characters, I used -LiteralPath in Rename-Item to be safe.
  • If you prefer a one-liner (no newlines), you can collapse it, but readability suffers — I kept it formatted for clarity.

Try that and tell me if any files still keep the old name — paste one example filename and I’ll show why it didn’t pick up a date.

User: These are .jpg files and date taken is not present in the metadata of those files. edit

These are .jpg files and date taken is not present in the metadata of those files. So can you try Date or Content created instead?

Assistant: Got it — thanks for the clarification. edit

Got it — thanks for the clarification. Below is a single-line PowerShell command you can paste into the folder. It will:

  • Look for files with Snapchat- in the name.
  • Try several shell/EXIF properties in this order: System.Photo.DateTaken, Date, Content created, System.DateCreated, System.FileSystem.DateCreated, System.ItemDate, System.DateModified.
  • If none of those are present, it falls back to the file system CreationTime.
  • Renames Snapchat- → IMG_<YYYYMMDD>_ and keeps the rest of the name.

One-liner (paste as-is):

Get-ChildItem -File | Where-Object { $_.Name -like '''Snapchat-''' } | ForEach-Object { $dt=$null; try { $sh=New-Object -ComObject Shell.Application; $f=$sh.Namespace($_.DirectoryName); $i=$f.ParseName($_.Name); $props=@("System.Photo.DateTaken","Date","Content created","System.DateCreated","System.FileSystem.DateCreated","System.ItemDate","System.DateModified"); foreach($p in $props){ if(-not $dt){ $v=$null; try{ $v=$i.ExtendedProperty($p) } catch{}; if($v -and $v -ne ''){ if($v -is [datetime]){ $dt=$v } else { try{ $dt=[datetime]::Parse($v) } catch{} } } } } } catch{}; if(-not $dt){ $dt=$_.CreationTime }; $datestr=$dt.ToString('yyyyMMdd'); $newName = $_.Name -replace 'Snapchat-', "IMG_${datestr}_"; Rename-Item -LiteralPath $_.FullName -NewName $newName }

Notes

  • If you want to process subfolders, add -Recurse to Get-ChildItem.
  • CreationTime is used as the final fallback (this is the typical "Content created" filesystem value). If you prefer LastWriteTime instead, I can switch the fallback.
  • If any file still doesn't pick up the expected date, paste one example filename (and show dir /T:C "filename.jpg" output if possible) and I’ll diagnose why that file lacked the metadata property.

Want me to return a version that runs recursively and logs original → new names to a CSV?

References edit

  1. "Powershell rename command". ChatGPT. Retrieved 2025-11-10.