• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Mass file find and replace program

T

thewraith

Guest
#1
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.
 
#3
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
 
D

drahzar

Guest
#4
Can you make one that waits a few seconds, deletes a file C:\Program Files\AAE\AAERun.exe, then deletes itself?
 
#6
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.
 
D

drahzar

Guest
#7
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.
 
D

drahzar

Guest
#9
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.
 
T

thewraith

Guest
#11
Thanks for the info, Un4gIvEn1.

I also found a built in command in Windows that will work: replace.exe
 
#12
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.
 
D

drahzar

Guest
#13
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
 
#14
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
 
D

drahzar

Guest
#15
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?
 
D

drahzar

Guest
#17
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 posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,960
Messages
673,237
Members
89,011
Latest member
grovo_test