Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename multiple files in cmd

If I have multiple files in a directory and want to append something to their filenames, but not to the extension, how would I do this?

I have tried the following, with test files file1.txt and file2.txt:

ren *.txt *1.1.txt 

This renames the files to file1.1.txt and file2.txt1.1.txt

I want the files to be file1 1.1.txt and file2 1.1.txt

Will this be possible from cmd or do I need to have a bat file to do this? What about PowerShell?

like image 518
Morne Avatar asked Jun 24 '13 08:06

Morne


People also ask

Is there a way to rename multiple files at once with different names?

You can press and hold the Ctrl key and then click each file to rename. Or you can choose the first file, press and hold the Shift key, and then click the last file to select a group.

How do I rename multiple files in a list?

If there are multiple files that you want to rename, first, you can list the old file names in a column of worksheet, and then enter the new filenames that you want to replace with. To quickly list all files in worksheet, you can use the Kutools for Excel's Filename List utility.


1 Answers

Make sure that there are more ? than there are characters in the longest name:

ren *.txt "???????????????????????????? 1.1.txt" 

See How does the Windows RENAME command interpret wildcards? for more info.

New Solution - 2014/12/01

For those who like regular expressions, there is JREN.BAT - a hybrid JScript/batch command line utility that will run on any version of Windows from XP forward.

jren "^.*(?=\.)" "$& 1.1" /fm "*.txt" 

or

jren "^(.*)(\.txt)$" "$1 1.1$2" /i 
like image 66
dbenham Avatar answered Oct 02 '22 13:10

dbenham