Windows – How to omit characters at the beginning of a filename while renaming it in Windows cmd

cmd.execommand linerenamewindows

I would like to know how to omit the first character of a filename while renaming the file in Windows cmd.

In my case I have bunch of files like:

#test1.txt
#test2.txt
#test3.txt
#test4.txt
#test5.txt

I would like to rename all the files in cmd prompt like

test1.txt
test2.txt
test3.txt
test4.txt
test5.txt

Files are in c:\myfiles\.

Best Answer

I faced a similar problem like this few months ago. It turned out removing characters at the beginning of file name is a little tricky using DOS. I came across this site which had a good solution for this.

All you need to do is cd into the directory containing the files and execute these two commands.

REN *.* " *.*" 
FOR %v IN (*.*) DO REN "%v" %v

This should replace the first character in all the file names.

The idea is to replace the number of unwanted characters with spaces using the first REN command then drop this spaces using the FOR loop and REN command.

Related Question