![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | rename files snippet I've got a group of people I work with who distributes executable files with _'s appended to the filenames. This little snippet made short work of that! $path = "\\server\share\folder" dir $path -Recurse -Include *_ | % { Rename-Item $_ $_.name.Substring(0,$_.name.length-1) } Line 1: Set the path to traverse. It can be local or a network share or any other Powershell provider (like a Onenote notebook or Sharepoint site). Line 2: Does a dir (aka Get-ChildItem) of the path, recursing into subfolders, and only includes those files which end in a "_" character. Pass the results into a foreach-object loop, abbreviated here by the % symbol. Line 3: Inside the loop, rename each item (as indicated by the $_ automatic variable). On each item, look at the Name property, and use the Substring method on that name. We want the substring beginning at the first character (first element in any array in Powershell is indicated by 0), and ending at the Length of the Name minus one. -- Hal Rottenberg blog: http://halr9000.com powershell category: http://halr9000.com/article/category...ng/powershell/ |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Batch rename of files | robm_jnb | PowerShell | 6 | 06-13-2008 05:23 AM |
| can you rename all files in folder at once? | Buggs1a | Vista General | 8 | 02-11-2008 09:31 AM |
| rename all files from a directory to a list of files ... | show3r@gmail.com | PowerShell | 4 | 08-25-2007 10:43 PM |
| rename files (lots of files for newbie) | light_wt | PowerShell | 3 | 06-08-2007 12:36 PM |
| cant delete files or rename files | nurselisa | Vista security | 2 | 05-03-2007 01:40 PM |