Jump to content

Neophyte needs help w/Script


Recommended Posts

Hi,

I'm not a programmer by any stretch of the imagination but think that I can get AutoIt to do what I want. However, I'm running into a snag. I am simply trying to create a script that will install Mozilla Firefox and then copy a config file to overwrite the default config which is created at install.

The problem I'm having is that Firefox puts its Prefs.JS config file in a folder which is unique to each install. I was able to search with AutoIT using the FindFileFirst command and bring back the directory name. I can set the name in a variable $file but when I try and copy the config file into the directory using the FileCopy command in conjunction with that variable it errors out. I'm sure my scripting is nonsense or I'm not using the right commands or I'm not using the variable correctly.

If anyone knows of a sample script out there that I could leverage or knows of a different way to accomplish what I'm trying to do, please let me know.

Thanks

KJ

Link to comment
Share on other sites

Ok. I told you I'm a neophyte. Here's what I cobbled together using the Help file. As I said it returns the directory name 7z8yc8fz.default as the variable but the file copy doesn't do anything. So, I'm sure it's my FileCopy command or I'm not finishing the search function first, or...

; Shows the filenames of all files in the current directory.

$search = FileFindFirstFile("C:\Documents and Settings\LocalAdmin\Application Data\mozilla\firefox\profiles\*.default")

; Check if the search was successful

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

MsgBox(4096, "File:", $file)

WEnd

FileCopy("c:\prefs.js", "$file")

; Close the search handle

FileClose($search)

Link to comment
Share on other sites

Reformatted:

; Shows the filenames of all files in the current directory.
$search = FileFindFirstFile("C:\Documents and Settings\LocalAdmin\Application Data\mozilla\firefox\profiles\*.default")  

; Check if the search was successful

While 1
    $file = FileFindNextFile($search) 
    
    
    If @error Then ExitLoop
    
    MsgBox(4096, "File:", $file)
WEnd

FileCopy("c:\prefs.js", "$file")

; Close the search handle
FileClose($search)

Edited by Fulano

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Link to comment
Share on other sites

I see 2 things wrong.

The MsgBox that popped up with "7z8yc8fz.default" in it should have been your first clue.

It is just the name of the folder, but the FileCopy function needs the full path for the destination.

Second, in your FileCopy function you have the destination as "$file" which is a string not a variable.

Lose the quotation marks.

Fulano's reformatting of the code makes that last part stand out.

- Hope this helps.

Edited by Raven1
Link to comment
Share on other sites

Also as you haave spaces in the path you will have to do something like FileFindFirstFile(" 'C:\Documents and Settings\LocalAdmin\Application Data\mozilla\firefox\profiles\*.default' ") else 'C:\Documents' might be used as the arg.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

  • 3 weeks later...

Okay,

I swear I took the above feedback and tried the following and it worked a couple days ago:

; Finds the name of the custom folder.

$search = FileFindFirstFile("C:\Documents and Settings\NIT\Application Data\mozilla\firefox\profiles\*.default")

$file = FileFindNextFile($search)

FileCopy("c:\WFMTemp\prefs.js", $file, 1)

; Close the search handle

FileClose($search)

However, now it doesn't!!!

I'm losing my mind. I I can get the folder name in the string $file but can't then copy the file into that folder. It either doesn't copy anything or it puts it in the profiles folder and dead ends there.

This shouldn't be that hard. I apologize for being so thick but really need some help scripting this "simple" file copy.

Thanks in advance for any help.

Link to comment
Share on other sites

Your $file just has the folder/file name found in it, without the full path. Maybe you need to add the rest of the path:

$sDir = "C:\Documents and Settings\NIT\Application Data\mozilla\firefox\profiles"
$search = FileFindFirstFile($sDir & "\*.default")
If @error = 0 Then
    $file = FileFindNextFile($search)
    If @error = 0 Then
        $file = $sDir & "\" & $file
        FileCopy("c:\WFMTemp\prefs.js", $file, 1)
    EndIf
EndIf

Some error checking couldn't hurt, too.

:(

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...