Computing.Net > Forums > Disk Operating System > Scripting Rename/Replace

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Scripting Rename/Replace

Reply to Message Icon

Name: moneymonk
Date: April 6, 2009 at 11:07:17 Pacific
OS: Windows XP
CPU/Ram: 1GB
Product: Dell / OPTIPLEX 755
Subcategory: General
Comment:

periodically i am required to navigate to dozens of folders on several servers and rename a file I will call "file.exe" to "fileYYYYMMDD.exe" and replace the old with a new file.exe. file.exe is named such in all folders, and the rename will be to today's date.

i was hoping to create a custom script on each server which gives paths to all the applicable subdirs where file.exe exists and would automate the rename old, copy new, paste new.

any assistance would be much appreciated.

thank you-
Mike



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: April 6, 2009 at 12:53:28 Pacific
Reply:

I guess you're using XP. [You're in the DOS forum.]

Is the script to be run on each server?


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: moneymonk
Date: April 6, 2009 at 13:05:21 Pacific
Reply:

Yes, using XP. the servers are all Server 2003.

I'm looking for sort of a template for a .bat that I can customize for the subdirs of each server. So, yes I expect the script to run locally on each server as needed, but i dont expect it to be "one size fits all". the constants will be the name of the orig/old file.exe, new file.exe, and the format for renaming the old file.exe. the variables will be the names of the subdirs the old file.exe resides within.

Apologies for posing to the wrong forum.

Again, yr assistance is appreciated.

Mike


0

Response Number 3
Name: Mechanix2Go
Date: April 6, 2009 at 15:42:56 Pacific
Reply:

As posted, this won't DO any REN or COPY but will preview what's to be done. To activate, edit out the 2 ECHOs in the lines after FOR.

It finds and renmaes the file.exe files on the current drive.

========================
:: ren all file.exe and copy fresh

@echo off & setLocal EnableDelayedExpansion

call :YMD

for /f "tokens=* delims=" %%a in ('dir/s/b/a-d \file.exe') do (
echo ren %%a !year!!month!!dat!%%~Na%%~Xa
echo copy file.exe %%~Fa
)
goto :eof

::===========================================
:YMD

>> d.d echo E 0100 B4 2A CD 21 B4 4C CD 21
>> d.d echo N DAY.COM
>> d.d echo RCX
>> d.d echo 8
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 F0 B4 4C CD 21
>> d.d echo N MONTH.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 89 C8 B4 4C CD 21
>> d.d echo N YEAR.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 D0 B4 4C CD 21
>> d.d echo N DAT.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo Q

debug < d.d > nul
del d.d

dat
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set dat=0%%a
for %%a in ( 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) do if errorlevel %%a set dat=%%a
echo Date %dat%

day
if errorlevel 0 set day=Sunday
if errorlevel 1 set day=Monday
if errorlevel 2 set day=Tuesday
if errorlevel 3 set day=Wednesday
if errorlevel 4 set day=Thursday
if errorlevel 5 set day=Friday
if errorlevel 6 set day=Saturday
echo Day %day%

month
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set month=0%%a
for %%a in ( 10 11 12) do if errorlevel %%a set month=%%a
echo Month %month%

year
if errorlevel 215 set Year=2007
if errorlevel 216 set Year=2008
if errorlevel 217 set Year=2009
if errorlevel 218 set Year=2010
echo Year %Year%

del day.com
del month.com
del year.com
del dat.com
::== DONE

goto :eof


=====================================
If at first you don't succeed, you're about average.

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Scripting Rename/Replace

DOS Scripting / Rename files www.computing.net/answers/dos/dos-scripting-rename-files/12240.html

replace characters in txt www.computing.net/answers/dos/replace-characters-in-txt/13669.html

repl. some in hundr. files! www.computing.net/answers/dos/repl-some-in-hundr-files/11681.html