Skip to content

Instantly share code, notes, and snippets.

@skarfie123
Created August 5, 2023 11:43
Show Gist options
  • Save skarfie123/d05d77fd7c9375d3d5dc4ddcb72c7dbd to your computer and use it in GitHub Desktop.
Save skarfie123/d05d77fd7c9375d3d5dc4ddcb72c7dbd to your computer and use it in GitHub Desktop.
add suffix to files in a folder
# Add suffix in place
Get-ChildItem -Recurse | Where-Object { !$_.PSIsContainer } | ForEach-Object {
Rename-Item $_.FullName -NewName "$($_.BaseName)-$($_.Directory.Name)$($_.Extension)"
}
# Move to parent with suffix
Get-ChildItem -Recurse | Where-Object { !$_.PSIsContainer } | ForEach-Object {
Move-Item $_.FullName -Destination "$($_.Directory.Parent.FullName)\$($_.BaseName)-$($_.Directory.Name)$($_.Extension)"
}
# Copy to parent with suffix
Get-ChildItem -Recurse | Where-Object { !$_.PSIsContainer } | ForEach-Object {
Copy-Item $_.FullName -Destination "$($_.Directory.Parent.FullName)\$($_.BaseName)-$($_.Directory.Name)$($_.Extension)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment