Replace or delete certain characters from filenames of all files in a folder
Dir | Rename-Item -NewName { $_.Name -replace " ","_" }
EDIT :
Optionally, the Where-Object command can be used to filter out ineligible objects for the successive cmdlet (command-let). The following are some examples to illustrate the flexibility it can afford you:
-
To skip any document files
Dir | Where-Object { $_.Name -notmatch "\.(doc|xls|ppt)x?$" } | Rename-Item -NewName { $_.Name -replace " ","_" }
-
To process only directories (pre-3.0 version)
Dir | Where-Object { $_.Mode -match "^d" } | Rename-Item -NewName { $_.Name -replace " ","_" }
PowerShell v3.0 introduced new Dir flags. You can also use Dir -Directory there.
-
To skip any files already containing an underscore (or some other character)
Dir | Where-Object { -not $_.Name.Contains("_") } | Rename-Item -NewName { $_.Name -replace " ","_" }
PowerShell: How do I append a prefix to all files in a directory?
Get-ChildItem | Rename-Item -NewName { "Prefix_" + $_.Name }
How to Use PowerShell and 7zip to create individual zip file for each .dmp file in a directory
-
Start up PowerShell from the Start menu
-
Make sure to 'run as administrator'
-
-
Move to the folder where your .dmp files are located
-
Use the following command line script to kick off the processing of the .dmp files
dir *.dmp | ForEach-Object { & "C:\Program Files\7-Zip\7z.exe" a -tzip ($_.Name+".zip") $_.Name } -
Here is a break down of the commands
-
dir *.dmp
-
selects all files in the directory
-
use a different extension for different file types
-
-
|
- passes the results of the first command to the next
- ForEach-Object
- loops thru all the elements from the first command
- "C:\Program Files\7-Zip\7z.exe"
- The path on my PC for the 7z.exe command line executable
- a
- The 7zip command to add to an archive
- -tzip
- the 7zip command to create a zip archive
- ($_.Name+".zip")
- the 7zip command to name the archive created
- $_.Name
- the PowerShell command to get the full name of the file
- +".zip"
- adds the .zip extension to the archive created
- $_.Name
- the 7zip command to name the archive created
- $_.Name
- the 7zip command for the file to archive
- the PowerShell command to get the full name of the file
-