It can make you start. (There are probably much more concise ways, but it works and is read when you need to support it later. :-))
I created the folder C:\TempFiles
and created the following files in this folder:
TestFile1.txt TestFile2.txt TestFile3.txt TestFile4.txt
(I created them in an old fashioned way, I'm afraid. <g>. I used
for /l %i in (1,1,4) do echo "Testing" > TestFile%i.txt
from the actual command line.)
Then I opened PowerShell ISE
in the Start menu and ran this script. It creates an array ( $files
) containing only the file names, and processes each of them:
cd \TempFiles $files = gci -name *.txt foreach ($file in $files) { $thename = $file.substring(4); rename-item -path c:\TempFiles\$file -newname $thename }
This left a folder containing:
File1.Txt File2.Txt File3.Txt File4.Txt File5.Txt
To run the script from the command line, you need to change some default Windows security settings. You can find out about them using the PowerShell ISE
help file (from the menu) and searching about_scripts
or by running help about_scripts
from the ISE
prompt. See the How To Run A Script
subsection in the help file (it is much easier to read).
source share