Jump to content
Sign in to follow this  
ontheteam

Obtaining a file path of a newly created directory/folder

Recommended Posts

ontheteam

I primarily use AutoIt for doing unattended application setups.

I am trying to write a script to install a custom user profile in Firefox for Windows. Firefox does not create the profile directory until its first run, but upon first run it creates a new user profile here:

"%USERPROFILE%\Application Data\Mozilla\Firefox\Profiles\uf0d7p36.default\"

The problem I am running into is that the final directory is named randomly; in this case "uf0d7p36.default" could just as well be "whatever.default". How can I write a script that will discover the name of this folder? Upon first install, this is the ONLY directory/folder inside

"%USERPROFILE%\Application Data\Mozilla\Firefox\Profiles\"

Anyway, my idea for the script is this:

Run("firefox.exe")
WinWait("Import Wizard",,10);wait for Firefox to create its profile structure
ProcessClose("firefox")

;Now the script needs to discover the path of the newly created profile directory, so I can tell 7zip where to extract the profile to.

Other info:

Not sure if this is useful, but there is a text file "%USERPROFILE%\Application Data\Mozilla\Firefox\Profiles\profiles.ini" that provides Firefox with this info:

[General]
StartWithLastProfile=1

[Profile0]
Name=default
IsRelative=1
Path=Profiles/uf0d7p36.default
Default=1

Also, that directory name is listed nowhere in the registry.

I'd be grateful for any assistance.

Share this post


Link to post
Share on other sites
monoceres

Since the profiles directory only contains this directory all you have to do is this:

#include <File.au3>
$data=_FileListToArray(@AppDataDir&"\Mozilla\Firefox\Profiles\","*.default",1)
MsgBox(0,"Firefox dir",$data[1])

Edit: Improved the example

Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
ontheteam

Since the profiles directory only contains this directory all you have to do is this:

#include <File.au3>
$data=_FileListToArray(@AppDataDir&"\Mozilla\Firefox\Profiles\","*.default",1)
MsgBox(0,"Firefox dir",$data[1])

Edit: Improved the example

I get this error with the example script:

Line 15 (File "C:\Documents and Settings\Prime\Desktop\New AutoIt v3 Script.AU3"):

MsgBox(0,"Firefox dir",$data[1])

MsgBox(0,"Firefox dir",^ ERROR

Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.

Edited by ontheteam

Share this post


Link to post
Share on other sites
ontheteam

Nevermind that last post. The error was in the _FileListToArray flag setting of 1 (files only) instead of 2 (folders).

Thank you for pointing the way.

Edited by ontheteam

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.