Page 1 of 1

how to add several characters to the name of all files

Posted: 09 Feb 2012 05:03
by Mohammad_Dos
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?

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

Posted: 09 Feb 2012 07:00
by Squashman

Code: Select all

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

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

Posted: 09 Feb 2012 08:54
by Mohammad_Dos
thank u :wink:
but! is there a way to do this work for all files in the folder with any format?

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

Posted: 09 Feb 2012 12:22
by Squashman
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.

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

Posted: 09 Feb 2012 14:58
by Ocalabob
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.