Mass file find and replace program

T

thewraith

Guest
My company is trying to upgrade a program that every one of our users erm...well...use. The upshot is that part of the upgrade requires the replacement of an ini file on thier networked private drives. This ini file lives in different spots for different people.

I personally don't want to visit 600+ private drives to do this replacement so I was wondering if anyone knows of a program or code chunk that will search a Windows storage volume and replace every file of a given name with a new copy from a specified location.

I've found zillions of proggies that do text replacement within files but nothing that does wholesale replacement.
 
How about this... (this would be a batch file)

--------

@echo off
dir /s /b oldfile.ini>>a.txt
for /f %%i in (a.txt) DO echo copy newfile.ini %%i>>runfile.bat
runfile.bat

--------

OK... so what this does is search all subdirectories from the root of where you run it and dumps the results into a text file in bare format (where if x were your drive and you were searching for abc.ini it would dump x:\folder\folder\abc.ini to the text file.

The FOR command takes each instance found in the text file and adds "copy newfile.ini %%i" where %%i is the information dumped to the previous text file, one at a time. This information is dumped to the runfile.bat file and would look like this...

copy newfile.ini x:\folder\folder\oldfile.ini
copy newfile.ini x:\folder\folder\folder\oldfile.ini

get it?

Then the next line launches the batch file. You can exclude this and review the batch file first and launch it seperately if you would like. If the files reside on a network drive then you shoudl probably map the drive on your local PC (the root of it) and run the batch file from a command prompt. You can remove the @echo off command if you wish to see what it is doing instead of hiding it all. Please let me know if this works for you.

Did I mention batch scripts are my forte? I can make a batch script to do just about anything. :)


EDIT:
Oh... I forgot to mention... it's probably a good idea to include quotes around your locations in case there are any spaces....

such as:

for /f %%i in (a.txt) DO echo copy newfile.ini "%%i">>runfile.bat
 
Can you make one that waits a few seconds, deletes a file C:\Program Files\AAE\AAERun.exe, then deletes itself?
 
what need would you have to wait a few seconds? how many seconds? and yes... :)
 
because of the limitations of batch scripting, creating timers isn't quite that easy. You could use it to create an AT statement to run at a certain time to run the delete command on the file.
 
It's for a custom uninstall, it has to wait because the .exe has to run the batch, then close itself before the batch deletes it.
 
what are you using to create the uninstaller? There are usually options to "wait" when running something.
 
The uninstall is part of a visual basic program. The uninstall is part of the main problem, I want to make it easy to uninstall, so instead of using the vb uninstaller, be able to click a button and it deletes itself.
 
Thanks for the info, Un4gIvEn1.

I also found a built in command in Windows that will work: replace.exe
 
Glad I could help...

drahzar: Here you go. This will create a timer and execute whatever you wish when it is done.

@echo off
set secstowait=15
echo %time%>time.txt
for /f "tokens=3 delims=:." %%i in (time.txt) do set timestart=%%i
set /a timestop=%timestart%+%secstowait%
if "%timestop%" GTR "60" set /a timestop=%timestop%-60
if "%timestop%" == "0" set timestop=00

:start
echo %time%>time.txt
for /f "tokens=3 delims=:." %%i in (time.txt) do set timestart=%%i
if "%timer%" == "0" goto end
set /a timetest=%timestart%+%secstowait%
if "%timetest%" GTR "60" set /a timestart=%timestart%-60
set /a timer=%timestop%-%timestart%
if "%timer%" == "%timerchange%" goto timer
if "%timer%" == "%secstowait%" goto timer
goto start

:timer
cls
echo Program will exit in %timer% seconds...
set /a timerchange=%timer%-1
goto start

:end
cls
pause

Change "set secstowait=15" to any numerical value you choose (this script will not allow over 59 seconds)

Change the "pause" command at the end to be anything you wish.. this command was only there for testing. You can make it delete a file at that time or do anything else.

Let me know if this works for you.

Edit: forgot to mention that you should take the information above and save it to a file with a .bat or .cmd extension. This file will ONLY work in Windows 2000 or XP. Windows 98/ME do not have the batch script options that the "NT" OSes have.
 
Hrmm, is there any way to get it to work on windows 98? cause thats what i use. if it's too hard don't bother, i'll try and find another workaround
 
the options for batch scripts in Windows 98 will not allow for this to be done in this method. The FOR command as well as others just aren't available. Sorry
 
I found something else to try, it's a command called Start w/ and then the program name. It opens the program, then waits till that program finishes to execute. I don't always want it to execute though, any suggestions?
 
the start function does have a wait option (/w).

Explain in more detail what you are wanting to do...
 
so it's part of the start function then? I need it to wait until the end of the program to execute, using win 98, is there a way a set it to wait for a program it doesn't start?
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back