1. remove some text on file name of all files: e.g. “TVBOXNOW ”
1 |
ls | Rename-Item -NewName { $_.name -replace "TVBOXNOW ", "" } |
2. move up one level of files in each directory, e.g. c:\folder1\folder2\file3 to c:\folder1\file3
1 2 3 4 5 6 |
$files = Get-ChildItem -Recurse "c:\folder1" | where {$_.PSIScontainer -eq $false} foreach ($file in $files) { $destinationFolder = Split-Path -Parent $file.Directory.FullName move-item $file.FullName $destinationFolder } |
3. Remove files by extension for all subdirectories: e.g. .url / .nfo
1 |
Get-ChildItem -File -Include *.url,*.nfo -Recurse | foreach ($_) {Remove-Item $_.FullName} |
4. see unique file extension in all subdirectories
1 |
Get-Childitem -File -Recurse | Select-Object Extension -Unique |
5. file name format: xxxx.2013.zzzz, strip out .zzzz. “-WhatIf” for dry run
1 |
Get-ChildItem | ForEach-Object -Process { Rename-Item -Path $_.Name -NewName ($_.name -replace '(.*)(\d{4})(.*)$', '$1$2') -WhatIf } |
6. for all pdf or epub file, rename filename as folder name
1 2 |
Get-ChildItem -Recurse | Where-Object { $_.Extension -eq ".pdf" -or $_.Extension -eq ".epub" -and !$_.Name.StartsWith($_.Directory.Name) } | rename-item -newname {$_.Directory.Name + $_.Extension } -WhatIf |