Mass file find and replace program

Discussion in 'Windows Desktop Systems' started by thewraith, Sep 23, 2003.

  1. thewraith

    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.
     
  2. coathanger007

    coathanger007 Tomorrow Tweaking Today

    Messages:
    1,520
    Location:
    Australia
  3. Un4gIvEn1

    Un4gIvEn1 Moderator

    Messages:
    1,084
    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
     
  4. drahzar

    drahzar Guest

    Can you make one that waits a few seconds, deletes a file C:\Program Files\AAE\AAERun.exe, then deletes itself?
     
  5. Un4gIvEn1

    Un4gIvEn1 Moderator

    Messages:
    1,084
    what need would you have to wait a few seconds? how many seconds? and yes... :)
     
  6. Un4gIvEn1

    Un4gIvEn1 Moderator

    Messages:
    1,084
    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.
     
  7. drahzar

    drahzar Guest

    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.
     
  8. Un4gIvEn1

    Un4gIvEn1 Moderator

    Messages:
    1,084
    what are you using to create the uninstaller? There are usually options to "wait" when running something.
     
  9. drahzar

    drahzar Guest

    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.
     
  10. drahzar

    drahzar Guest

    main problem = main program
     
  11. thewraith

    thewraith Guest

    Thanks for the info, Un4gIvEn1.

    I also found a built in command in Windows that will work: replace.exe
     
  12. Un4gIvEn1

    Un4gIvEn1 Moderator

    Messages:
    1,084
    Glad I could help...

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

    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.
     
  13. drahzar

    drahzar Guest

    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. Un4gIvEn1

    Un4gIvEn1 Moderator

    Messages:
    1,084
    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
     
  15. drahzar

    drahzar Guest

    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?
     
  16. Un4gIvEn1

    Un4gIvEn1 Moderator

    Messages:
    1,084
    the start function does have a wait option (/w).

    Explain in more detail what you are wanting to do...
     
  17. drahzar

    drahzar Guest

    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?