Rename first 20 characters of every filename in a file

Question:

I am trying to write a script in powershell to remove the first 20 characters of every MP3 filename in a folder, I have created a file ‘test.ps’ and inserted the powershell code below into it,

When I run this file in powershell.exe nothing happens,

Can anyone help? Thanks.

Answer:

This may get you started. (There are probably much more concise ways, but this works and is readable when you need to maintain it later. 🙂 )

I created a folder C:\TempFiles, and created the following files in that folder:

(I created them the old-fashioned way, I’m afraid. <g>. I used

from an actual command prompt.)

I then opened PowerShell ISE from the start menu, and ran this script. It creates an array ($files), containing only the names of the files, and processes each of them:

This left the folder containing:

In order to run a script from the command line, you need to change some default Windows security settings. You can find out about them by using PowerShell ISE‘s help file (from the menu) and searching for about_scripts or by executing help about_scripts from the ISE prompt. See the sub-section How To Run A Script in the help file (it’s much easier to read).

Source:

Rename first 20 characters of every filename in a file by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply