keypuncher Posted April 23, 2008 Posted April 23, 2008 I am trying to come up with a code to work with files in a directory that has a variable name on different systems.I can put in the variables to get so far into the directory structure / hierarchy. However at the point where I am at least 1 level above the ultimate directory the folder created will have different names depending on the system it was installed in. Example "F:\Documents and Settings\user\Application Data\Mozilla\Firefox\Profiles\3dsnasxvw.default" on system Amight be "G:\Program Files\John\Application Data\Mozilla\Firefox\Profiles\5cvbasdfg.default" on system BI might be able to use wildcards to find the directory structure down to and including "profiles" but the directory "3dsnasxvw.default" can have any name.default Ultimately I want to have the program work with editing files within the randomly named directory.So any ideas on how to have the script find and execute the path to that folder so I can have it auto edit files contained therin?If it helps in this example the folder is created by Firefox when it is installed.Ultimately I want to be able to use this program on most any windows based computer without having to rewrite it for that particular system.For now I am experimenting on a WinXP Pro system.
MHz Posted April 23, 2008 Posted April 23, 2008 You can FileFindFirstFile() to get a search handle and then use FileFindNextFile() to get the matching filenames. Getting the default folder in Firefox is possible with something like this $handle_search = FileFindFirstFile(@AppDataDir & '\Mozilla\Firefox\Profiles\*.default') If $handle_search <> -1 Then $folder = FileFindNextFile($handle_search) If Not @error Then MsgBox(0x40000, 'Folder found', $folder) EndIf FileClose($handle_search) EndIf See the help file for further examples. Use FileFindNextFile() within a loop for multiples files to find
keypuncher Posted April 23, 2008 Author Posted April 23, 2008 Thank you MHZ. That works nicely for locating the correct folder. However after locating (nowknowndirname) I do not want a message box to pop up with the name. Most of this is designed to run in the background. I am looking to have the folder name it comes up with (nowknowndirname) then inserted into the same program so I can have it immediately use some file utilities such as filerecycle on files contained within (nowknowndirname). So I guess I need to have the result of $folder automatically inserted into the next line, something like this: If $answer = 1 then $handle_search = FileFindFirstFile(@AppDataDir & '\Mozilla\Firefox\Profiles\*.default') If $handle_search <> -1 Then $folder = FileFindNextFile($handle_search) If Not @error Then FileRecycle($folder\extensions.cache) EndIf FileClose($handle_search) EndIf[/autoit] This is just a partial. Obviously this does not work but it is the basic idea. I am having trouble coming up with the syntax. I look to have this automated so the user does not have to do any input once started. I believe my problem is mostly with the line: FileRecycle($folder\extensions.cache)
MHz Posted April 23, 2008 Posted April 23, 2008 (edited) Thank you MHZ. That works nicely for locating the correct folder. However after locating (nowknowndirname) I do not want a message box to pop up with the name....It is an example to find the folder. I was hoping that you would use some initiative and change it to suit your need. This may help you along some more. Global $answer = 1 If $answer = 1 then $path = @AppDataDir & '\Mozilla\Firefox\Profiles' $handle_search = FileFindFirstFile($path & '\*.default') If $handle_search <> -1 Then $folder = FileFindNextFile($handle_search) If Not @error Then FileRecycle($path & '\' & $folder & '\extensions.cache') EndIf FileClose($handle_search) EndIf EndIf Notice the full path used for FileRecycle() parameter as the working directory is unknown AFAIK to use relative path. Edited April 23, 2008 by MHz
keypuncher Posted April 23, 2008 Author Posted April 23, 2008 MHZ I did try to use some initiative. It's just my old tired, burdened mind failed me. I had trouble getting from step A (locating the folder) to step B (using the info in another process). Now it is working well. I have been able to modify & incorporate what you offered in with what I was doing and it works nicely now. I am doing some more modifications and expansion, then more testing. Thanks again for your help It is an example to find the folder. I was hoping that you would use some initiative and change it to suit your need. This may help you along some more. Global $answer = 1 If $answer = 1 then $path = @AppDataDir & '\Mozilla\Firefox\Profiles' $handle_search = FileFindFirstFile($path & '\*.default') If $handle_search <> -1 Then $folder = FileFindNextFile($handle_search) If Not @error Then FileRecycle($path & '\' & $folder & '\extensions.cache') EndIf FileClose($handle_search) EndIf EndIf Notice the full path used for FileRecycle() parameter as the working directory is unknown AFAIK to use relative path.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now