Script or Batch to Rename Files

Hello Experts,

I need your help in creating a batch or script that will rename two files located in a shared folder. the two original files once generated by my program will always start with a fix letter A and B follow by the date.  The format is somewhat like this A00000000.XXX and B00000000.XXX
I need to rename these files to have the following format "NAME.NAME.name.A0000000.XXX and NAME.NAME.name.B0000000.XXX respectively. Basically the name of the original file adding the 3 words separated by periods to the beginning of the file name.
I will need to run this from a windows XP Pro workstation which is part of AD on a mix 2K and 2K3 domain my idea is to put this batch or script in the desktop and have the user double click on it to rename the file. i think it will actually be better to create one batch or script per file, since the orginals are created at different times of the day.
My knowledge on batch and scripting is very very limited therefore i'm posting this ? in hope for someone to create or guide me in the process of creating the script.
I thank you in advance.
WilsonJ
WilsonJAsked:
Who is Participating?
 
Steve KnightConnect With a Mentor IT ConsultancyCommented:

Sorry your files have a different path to my test one, remove the two _'s giving:

@echo off
SET newname=NAME.NAME.name
pushd \directoryname
for /f "tokens=*" %%a in ('dir /b /a-d A*.XXX') do rename "%%a" "%newname%.%%a" & echo Renaming %a to %newname%.%a
for /f "tokens=*" %%a in ('dir /b /a-d B*.XXX') do rename "%%a" "%newname%.%%a" & echo Renaming %a to %newname%.%a
popd
pause
0
 
Steve KnightIT ConsultancyCommented:
Try this... paste into notepad and save as namefiles.cmd

@echo off
SET newname=NAME.NAME.name
pushd \directoryname
for /f "tokens=*" %%a in ('dir /b /a-d A_*.XXX') do rename "%%a" "%newname%.%%a" & echo Renaming %a to %newname%.%a
for /f "tokens=*" %%a in ('dir /b /a-d B_*.XXX') do rename "%%a" "%newname%.%%a" & echo Renaming %a to %newname%.%a
popd
pause

It change into the relevant directory and gets a directory listing of files matching A*.XXX and then renames them by adding NAME.NAME.name to the front then does the same for B*.XXX.

If there is nothing that matches that pattern nothing happens

Steve
0
 
RobSampsonCommented:
Are your three words going to change with each file?  And how will you select which file to rename?  Will they always be placed in a specific folder?

Do you want the user prompted for the three words, or a folder to select?

Regards,

Rob.
0
 
WilsonJAuthor Commented:
That was it, thank you very much dragon-it
0
 
Steve KnightIT ConsultancyCommented:
No problem.

Steve
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.