Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/6910af03-f58c-800b-a67e-c1aff06d11d4
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== gpt-5 == === User: Help me with an inline Powershell command to rename bunch of files, which has 'Snapchat-' in it while keeping the rest … === 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: === 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: <syntaxhighlight lang="powershell">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 } </syntaxhighlight> ===== - Get-ChildItem -File — lists all files in the current directory. ===== '' 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"</code>— replaces the “Snapchat-” prefix with<code>IMG_YYYYMMDD</code>. * Rename-Item — renames the file in place. ===== If you have: ===== <syntaxhighlight>Snapchat-12345.jpg (Date: 2023-07-14) Snapchat-98765.mp4 (Date: 2024-02-01) </syntaxhighlight> After running: <syntaxhighlight>IMG_20230714_12345.jpg IMG_20240201_98765.mp4 </syntaxhighlight> Would you like it to also search through subfolders recursively? If yes, I’ll tweak it to handle that too.
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)