1.

Solve : Editing file names using bat files??

Answer»

First off I would like to thank the forum and knowledgable poster for there help here.
I got my little file done by reading here in the help batch files section and reading many other post,
but the last thing I would like to do but I just can not figure out, and that is how to read a file name into
a variable so I can edit the file name, not just rename it.
What I want to do is read an existing file name which consist of a name and a version# and replace the name
part of the file but keep the version #.
EX. oldfilename_001.abc to newfilename_001.abc

Thanksyou mean:
Code: [Select]ren oldfilename_*.abc newfilename_*.abc
??

anyway you can use for to get filenames...

Code: [Select]for /F %%F in ('dir /b *.abc') do echo %~nFQuote from: devcom on April 14, 2009, 04:10:56 PM

you mean:
Code: [Select]ren oldfilename_*.abc newfilename_*.abc
??

anyway you can use for to get filenames...

Code: [Select]for /F %%F in ('dir /b *.abc') do echo %~nF

Thanks for the reply, your 2ND example is beyond me, I did SEE that in another post and it did work as far as echoing to the screen but I was not able to modify it to work for me, however your first example( can`t believe I did not think of it) should do just fine.

ThanksWell the rename as simple as it seemed I was not able to use as it is a little more complicated than just renaming a file.
In my bat file, which runs under a CMD window in Vista, the original file gets copied then archived away. The copied file has
changes made to it and is then named for use. At this point I really have no way of TELLING which file goes with which file so I
hoping to take the version # out of the original file and have it added to the new file name. Simply renaming does not work.
The 2nd method devcon provided me does not work under my CMD window. I get "The syntax of the command is incorrect". After trying it in immeditate mode on the command line the %%F causes a "%%F was unexpected at this time error". Removing one of the % does allow it to work and changing the command "echo" to "set f =" does MAKE it an environmental variable showing the file name. That is what I was looking for and I assume at this point it would be easier to edit and just take the version # from the orginal file name. However that only worked when TYPE on the command line.
Any idea what is causing the syntax error when the bat file is run?

Thankswhat is it that not working?

ren oldfilename_*.abc newfilename_*.abc
this will work as long as string length of oldfilename equal to string length of newfilename

type: dir/b *.abc
and post the few lines of the screen output here

single % is used on command prompt, when you write the code into batch file you use double percent %%.Again, I am lost.
What did you need FOR for?
Code: [Select]RENAME *_???.abc NewName_???.abc
Seems to be that Dev's for loop is to find all files in the current directory and sub-dirs that have the abc extension, and everytime it finds a file with that then show the name of the file.

if he means %~nl instead of %~nFThanks guys without your help as I would never had gotten this without it.

Code: [Select]for /F %%F in ('dir /b *.zip') do set 1 = %%F
This gives me environmental variable 1, as seen under set command, = oldfilename_date_version_type.zip.
I assume I can edit the variable 1 to take date_version_type from the old file and add that to the new file
after changes are made to the file to give me newfilename_date_version_type.abc.

Thanks for the help and I`ll see if I can edit the variable tonight.


Discussion

No Comment Found