Here are some handy tricks for batch renaming files and for printing a directory listing of files.
First, download the PowerShell Here executable: powershellhere
Batch Renaming Files
Using PowerShell (included with Windows) you can rename a large series of files in a batch. For example, let’s say there is a large number of files such as those shown below:
CAE_T501_Doc_Name1.docx
CAE_T501_Doc_Name2.docx
CAE_T501_Doc_Name3.docx
CAE_T501_Doc_Name4.docx
CAE_T501_Doc_Name5.docx
…
To change them all from CAE_T501_Doc to CaeT5Doc, for example, you would:
- Launch PowerShell using either the PowerShell here context menu listed below, or go to the Windows button > Search > PowerShell, then navigate to your directory using “cd”.
- Copy and paste the script below:
Dir | Rename-Item –NewName { $_.name –replace ““,”” } - The Find field is located in the first set of quotes, and the Replace text is in the second set of quotes. Therefore, the example above would look like this:
Dir | Rename-Item –NewName { $_.name –replace “CAE_T501_Doc “,”CaeT5Doc” } - Press enter
That’s it.
PowerShell here
The PowerShell Here context menu feature opens a PowerShell command prompt from the directory you are currently viewing in File Explorer. (If you’re already familiar with Command Prompt Here, it’s the same deal.)
Note: This is particularly useful for SharePoint where getting a command prompt can be difficult.
Save and install the powershellhere.inf file. (To install, view the file in File Explorer and select Install from the context menu.)
To use PowerShell here, right click on a directory:
PowerShell and Renaming in SharePoint
To use PowerShell in SharePoint to rename large numbers of files, perform the following steps.
- Go to Explorer View by either selecting Explorer View from the view dropdown in SP 2007 or select Library Tools>Library>Open with Explorer in 2010.
- Navigate up one directory to show your desired directory in the right pane
- Right-click on the directory to open the context window
- Run the script shown above
Hope this is helpful and can save time in the future for big renaming jobs,
Mike