Jump to content

Search & Replace File


Recommended Posts

Are you looking in a given set of folders? Or searching an entire drive?

[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]
Link to comment
Share on other sites

Also, when you say you're looking to search for a file, and then replace it. Are you looking at the file name? Replacing it how?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I am trying to replace a specific file in the following direcotry %APPDATA%\Mozilla\Firefox\Profiles\68miioew.default whereas

68miioew.default
is different for all the users. How do i accomplish this? I am actually replacing this file from AppData & also from the program directory that is why i need a script which will search the file name lets say (abc.js) & replace.

Edited by teeboi
Link to comment
Share on other sites

I'm working on a quick script to give you an example, but I need to know what you are doing to each folder. Which of the following describes you?

1) You are replacing ALL profiles with a separate profile

2) You are checking to see which profile each user has and then doing something

3) Other

[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]
Link to comment
Share on other sites

Well, I couldn't find an abc.js file, so I assume that's not the actual file name and as such I can't give you exactly what you need. However, here is the basic concept:

#Include <File.au3>

$aFolders =_FileListToArray("C:\Documents and Settings","*",2)                                              ;This will list all of the folders in the main Documents and Settings folder
$sCopyFolder = "Path to the folder to be copied"                                                            ;This is the path to the folder you wish to be copied

For $i = 1 To UBound($aFolders) - 1                                                                         ;This will repeat for each profile folder
    $sFolder = "C:\Documents and Settings\" & $aFolders[$i] & "\Application Data\Mozilla\Firefox\Profiles\" ;The location of each individual profiles folder
    If FileExists($sFolder) = 1 Then                                                                        ;Check to see if the given user has a Firefox profile folder, if so, then
        $aFiles = _FileListToArray($sFolder)                                                                ;This will pull in the name of the one profile folder. I.E. 68miioew.default
        DirRemove($sFolder & $aFiles[1],1)                                                                  ;This will delete out the current .default folder
        DirCopy($sCopyFolder,$sFolder & $aFiles[1])                                                         ;This will copy the entire .default folder to the new location
    EndIf
Next                                                                                                        ;This repeats the For loop

DONT RUN THIS AS IS! Currently, it will replace an entire directory as that is what I thought you were doing. You can edit this basic concept to fit your needs though, as most of the code will be the same.

Let me know if you have any questions.

- Fett

[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...