how to add several characters to the name of all files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Mohammad_Dos
Posts: 84
Joined: 08 Sep 2010 10:25
Location: Iran,Kashan
Contact:

how to add several characters to the name of all files

#1 Post by Mohammad_Dos » 09 Feb 2012 05:03

i want to add several characters (+++) to name of all files in a folder. i use this:

Code: Select all

ren *.* +++*.*

but names change like these:

new file.txt ------> +++ file.txt
extra.wmv ------> +++ra.wmv

can somebody help me?

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: how to add several characters to the name of all files

#2 Post by Squashman » 09 Feb 2012 07:00

Code: Select all

for %%G in (*.txt *.wmv) do rename "%%G" "+++%%G"

Mohammad_Dos
Posts: 84
Joined: 08 Sep 2010 10:25
Location: Iran,Kashan
Contact:

Re: how to add several characters to the name of all files

#3 Post by Mohammad_Dos » 09 Feb 2012 08:54

thank u :wink:
but! is there a way to do this work for all files in the folder with any format?
Last edited by Mohammad_Dos on 09 Feb 2012 12:33, edited 2 times in total.

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: how to add several characters to the name of all files

#4 Post by Squashman » 09 Feb 2012 12:22

Mohammad_Dos wrote:thank u :wink:

but! is there a way to do this work for all files in the folder with any format?

Use the wildcard character as the only character inside the parentheses.

Ocalabob
Posts: 79
Joined: 24 Dec 2010 12:16
Location: Micanopy Florida

Re: how to add several characters to the name of all files

#5 Post by Ocalabob » 09 Feb 2012 14:58

Greetings Mohammad_Dos,

In addition to Squashman's reply have a look here:

viewtopic.php?f=3&t=1525&p=5852#p5852

A simple modification may work for you. For example:

Code: Select all

@echo off
setlocal
attrib %0 +h
for /f "delims=" %%f in (
'dir /b *.*') do (
set name=%%~nxf
echo ren "%%~nxf" "+++%%~nxf"
)>>test_file.bat
attrib %0 -h



Best wishes.

Post Reply