File search and replace.

  • Thread starter Thread starter Scott Closter
  • Start date Start date
S

Scott Closter

Is there a command line utility (or even a GUI based
utility)that will allow you to search for all instances of
a file on a server (multiple drives and /or subfolders),
then replace the version of the file in those instances
with a specific version of the file you wish to deploy?
 
Scott said:
Is there a command line utility (or even a GUI based
utility)that will allow you to search for all instances of
a file on a server (multiple drives and /or subfolders),
then replace the version of the file in those instances
with a specific version of the file you wish to deploy?

Hi, Scott:

You can probably do this with a simple batch file. Here's
one way:

=====begin c:\cmd\demo\FindAndReplaceAll.cmd ====================
01. @echo off
02. setlocal
03. set file_to_be_replaced=%1
04. set new_file=c:\yourpath\newfile.xyz
05. set drives_to_search=c: j: k:
06. for %%a in (%drives_to_search%) do call :main %%a
07. goto :EOF
08. :main
09. pushd %1\
10. echo/Searching drive %1 for %file_to_be_replaced% - PLEASE WAIT.
11. for /f "tokens=*" %%a in (
12. 'dir /s /b %file_to_be_replaced%'
13. ) do (
14. echo del "%%a"
15. echo copy %new_file% %%~pa
16. )
17. popd
18. goto :EOF
=====end c:\cmd\demo\FindAndReplaceAll.cmd ====================

If this appears to do what you intend, then remove 'echo' from lines 14
and 15 to actually replace the found files.
 
Phil Robyn said:
Hi, Scott:

You can probably do this with a simple batch file. Here's
one way:

=====begin c:\cmd\demo\FindAndReplaceAll.cmd ====================
01. @echo off
02. setlocal
03. set file_to_be_replaced=%1
04. set new_file=c:\yourpath\newfile.xyz
05. set drives_to_search=c: j: k:
06. for %%a in (%drives_to_search%) do call :main %%a
07. goto :EOF
08. :main
09. pushd %1\
10. echo/Searching drive %1 for %file_to_be_replaced% - PLEASE WAIT.
11. for /f "tokens=*" %%a in (
12. 'dir /s /b %file_to_be_replaced%'
13. ) do (
14. echo del "%%a"
15. echo copy %new_file% %%~pa
16. )
17. popd
18. goto :EOF
=====end c:\cmd\demo\FindAndReplaceAll.cmd ====================

If this appears to do what you intend, then remove 'echo' from lines 14
and 15 to actually replace the found files.

Isn't this precisely what the REPLACE command is supposed to do? As I read
the "/?" docs, you would just have to run it once on each drive.


/Al
 
Al said:
Isn't this precisely what the REPLACE command is supposed to do? As I read
the "/?" docs, you would just have to run it once on each drive.


/Al
Hi, Al,

Yeah, you're right; REPLACE would probably be able to do this just fine. :-)
 
In said:
Is there a command line utility (or even a GUI based
utility)that will allow you to search for all instances of
a file on a server (multiple drives and /or subfolders),
then replace the version of the file in those instances
with a specific version of the file you wish to deploy?

You should specify the criteria perhaps.
If the filenames exactly match ...
If internal Version Info ....
etc.

Seems the mentioned replace.exe would address the first case.
 
Back
Top