1.

Solve : Adding a number to a filename?

Answer»

Hello,

I'm having trouble finding the right commands to rename existing files, by ADDING a number

For example:
I want to change all file names in a certain folder, by adding the nummer 7000 to the existing filename (and not change the extension of the file).

Does anyone have any idea?

Many thanks for your insight.

ShapeHow do you mean 'adding'
from 2009-02-17.txt to 7000-2009-02-17.txt
or
from 2009-02-17.txt to 9009-02-17.txt

The first is relatively simple :

ren 2009-02-17.txt 7000-2009-02-17.txt
The second really depends on what the file is called, as you would have to take the name, extract the part with the number, add 7000 and reinsert the result, then ren the old name to the new value

The file names in the directory are different.
For example three files are in the directory stored:
shape.pdf
telephone.xls
memo.doc

Now I want to rename these files (by command) to:
7000shape.pdf
7000telephone.xls
7000memo.doc

Referring to your answer, option two would be the right one, however, the number of files are in reality al lot more than three, and each have different names. Changing the names "manually" would take a lot of time

I've searched for commands such as "rename" and "replace", but couldn't find the right one.
The "rename" command for instance, doesn't add the 7000 but changes the first four tokens of the file name in 7000, if the command is: ren *.* 7000*.*

Is this perhaps even possible in DOS commands?Try this:

Code: [Select]set /p "rena=Enter the file name and extension:
ren %rena% 7000%rena%

Try that.I've tried it.
The command STILL changes the first four characters of the file name into 7000.It works fine here. renamed vert.txt to 7000vert.txt.Quote from: Shape on February 17, 2009, 10:18:51 AM

I've tried it.
The command still changes the first four characters of the file name into 7000.

You *SURE*? You have to be in the current directory of the files, too.A bit too quick in my answer....
It indeed put's the 7000 in front of the file name.
for instance:
shape.pdf
I fill in shape.* when prompted
Then it renames the file with the 7000 in front of it (7000shape.pdf)

It was however the meaning, that every file (whatever the name) should be changed.
GETTING close though!what about:
Code: [Select]echo add "7000" to beginning of all files in current directory?
cd
echo press Ctrl+Break to cancel, otherwise
pause
for %%P in (*.*) do ren %%P 7000%%P

as a batch file?So...You want it to be a loop, so you enter

Blank.pdf
V
7000Blank.pdf

Then continuing

john.xlm
V
7000john.xlm

Without opening, closing, opening, closing?Quote from: BC_Programmer on February 17, 2009, 10:32:23 AM
what about:
echo add "7000" to beginning of all files in current directory?
cd
echo press Ctrl+Break to cancel, otherwise
pause
for %%P in (*.*) do ren %%P 7000%%P
as a batch file?

THATS IT!
The code puts the 7000 in front of all the file names.

Many Thanks for you help! You have no idea, how many time this saves me

your welcome

may it give you many saved minutes of freecell lolYou beat me this time D:! Good job though.


Discussion

No Comment Found