Page 1 of 1
Add to a file
Posted: 17 Dec 2010 07:21
by I_Love_2_DOS
How can I add to a file name?
I have a directory called TEST.
Inside TEST there are 200 files (all of different names and extensions).
How can I add “a” in front of each name and still keep the same name and extension. i.e. c:\TEST\hello.txt will become c:\TEST\ahello.txt.
I want to use a batch file.
Re: Add to a file
Posted: 18 Dec 2010 05:05
by rfpd
i don't think that's possibel but i will see what i can do
Re: Add to a file
Posted: 18 Dec 2010 05:13
by rfpd
I found one code that change the first letter to a
Code: Select all
@echo off
rename "C:\Your\Folder\Destination\*.*" a*.*
Re: Add to a file
Posted: 21 Dec 2010 14:39
by ChickenSoup
This should do it:
Code: Select all
for /f "tokens=*" %a in ('dir /b') do rename "%a" "a%a"
Re: Add to a file
Posted: 23 Dec 2010 17:52
by rfpd
Nope ChickenSoupe that doesn't work.
Re: Add to a file
Posted: 24 Dec 2010 08:22
by !k
It's designed for command line.
In the batch you must double the %
Re: Add to a file
Posted: 24 Dec 2010 12:28
by Ocalabob
The lines below work for me with limited testing. Remove the word ECHO if $$$test.txt gives you the desired results.
Best wishes all.
@echo off
for /f "delims=" %%f in (
'dir /b *.*') do (
set name=%%~nxf
ECHO ren "%%~nxf" "a%%~nxf"
)>>$$$test.txt
set name=
Re: Add to a file
Posted: 27 Dec 2010 08:41
by ChickenSoup
ChickenSoup wrote:This should do it:
Code: Select all
for /f "tokens=*" %a in ('dir /b') do rename "%a" "a%a"
Yes, inside a batch file it would be the following:
Code: Select all
for /f "tokens=*" %%a in ('dir /b') do rename "%%a" "a%%a"
Re: Add to a file
Posted: 27 Dec 2010 10:45
by rfpd
good job chicken soup it works