Skip to main content
Photo of DeepakNess DeepakNess

Remove first/last few characters from multiple files on Windows

Unproofread notes

Say, you have 100s of files like below, and you want to remove the first 11 characters (i.e. the date) from the start of each files on your Windows computer.

Doing it manually will take forever, but there's a quick PowerShell command that you can use. And here's the process:

  1. Open the folder, where you files are, in the File Explorer
  2. Press shift and right-click somewhere in the folder
  3. Select the "Open PowerShell window here" option or something similar, and
  4. Run the following command, and it will be done
get-childitem *.md | rename-item -newname { [string]($_.name).substring(11) }

Here I'm assuming that you have multiple .md files, and you want to remove the fist 5 characters from the file names. You can modify the command as per your use case and then use.

Now, if you want to remove the last few characters from filenames, here's how to do it:

Say, you have multiple files with names like below, and you want to remove the last 4 characters i.e. the numbers from filenames (but we've to keep the file extension .pdf here)

The similar way, open PowerShell in the folder and run the following command:

get-childitem *.pdf | rename-item -newname { $_.basename.substring(0,$_.basename.length-4) + $_.extension }

Here I'm assuming that you have multiple .pdf files, and you want to remove the last 4 characters from the filenames, while keeping the file extension .pdf.

Please note that this process is irreversible, so I would recommend that you copy all the files to another folder and then try running these commands to avoid any mistakes.

Also, this command works only for the same type of file i.e. files having the same extension. If you have to rename multiple files of different extensions, you can repeat the process for each type of file.

Comment via email