Background:
I am trying to migrate the Firefox profiles from the local machines to the roaming profile directory of the user. Some users already have the profile located in their home drive, the majority does not.
I already tried to do this with the CCK Tool from Mike Kaply but unfortunately it's not migrating the Firefox profile directory to the roaming profile of the user, but instead just points to the roaming profile directory where no Firefox profile is located.
So, to work around this, I decided to create a batch, which looks in every user directory under the directory "home" for the directory "FirefoxProfile". If this folder does not exist, it would create it (hidden folder). Furthermore the script would loop through every local profile, search in every Firefox profile folder for the latest places.sqlite file (the bookmarks file of Firefox), copy it to the users FirefoxProfile folder under home and lastly copy the file profiles.ini to the users Firefox folder under AppData\Roaming\Mozilla.
If the folder FirefoxProfile under the user’s home directory does exist, the script would do the same steps as if the folder does not exist, but not create the folder FirefoxProfile.
The script I wrote does not run as expected. I tried to rewrite it (rearranged the quotes and brackets, reformat the code), but it always comes down to the following problems: The script deletes the parameter "/D" in the FOR loop. Also from there on the script doesn't recognize the "%%" variables correctly, instead it deletes the leading "%" character.
Furthermore something is wrong with the FOR /F loop. The output in the flie 3.txt is:
DIR /S /B /O:-D testuser1.V2\AppData\Roaming\Mozilla\Firefox\Profiles\places.sqlite home\testuser1\FireFoxProfile\Default
But it should give back something like this:
testuser1.V2\AppData\Roaming\Mozilla\Firefox\Profiles\lh15n9tq.default\places.sqlite home\testuser1\FireFoxProfile\Default
I would highly appreciate any help. Thanks in advance.
The script:
setlocal enabledelayedexpansion
SET HomeProfile=""
SET WSProfile=""
SET FFProfile=""
pushd \\srv-xyz\users
cd home
FOR /D %%A in (*) DO (
SET "HomeProfile=%%A"
if not exist !HomeProfile!\FireFoxProfile (
echo does not exist >> C:\tmp\1.txt
echo !HomeProfile!\FireFoxProfile\Default >> C:\tmp\2.txt
cd profile_WS
FOR /D %%B in (!HomeProfile!.V2) DO (
SET "WSProfile=%%B"
FOR /F "usebackq delims=" %%C IN ('DIR !WSProfile!\AppData\Roaming\Mozilla\Firefox\Profiles\places.sqlite /S /B /O:-D') DO (
SET "FFProfile=%%C"
echo !FFProfile! home\!HomeProfile!\FireFoxProfile\Default >> C:\tmp\3.txt
echo C:\tmp\profiles.ini !WSProfile!\AppData\Roaming\Mozilla\Firefox >> C:\tmp\4.txt
))
) ELSE (
echo !HomeProfile!\FireFoxProfile\Default >> C:\tmp\5.txt
FOR /D %%B IN (!HomeProfile!.V2) DO (
SET "WSProfile=%%B"
FOR /F "usebackq delims=" %%C IN ('DIR !WSProfile!\AppData\Roaming\Mozilla\Firefox\Profiles\places.sqlite /S /B /O:-D') DO (
SET "FFProfile=%%C"
echo !FFProfile! home\!HomeProfile!\FireFoxProfile\Default >> C:\tmp\6.txt
echo C:\tmp\profiles.ini !WSProfile!\AppData\Roaming\Mozilla\Firefox >> C:\tmp\7.txt)
))
)
popd
PAUSE
The scripts state:
To test the script, I replaced the actual code and made the script write its output to text files.
The Problem:
For every user the script fails like follows
V:\home>(
SET "HomeProfile=testuser1"
if not exist !HomeProfile!\FireFoxProfile (
echo does not exist 1>>C:\tmp\1.txt
echo !HomeProfile!\FireFoxProfile\Default 1>>C:\tmp\2.txt
cd profile_WS
FOR / %B in (!HomeProfile!.V2) DO (
SET "WSProfile=%B"
FOR /F "usebackq delims" %C IN ('DIR /S /B /O:-D !WSProfile!\AppData\Roaming\Mozilla\Firefox\Profiles\places.sqlite') DO (
SET "FFProfile=%C"
echo !FFProfile! home\!HomeProfile!\FireFoxProfile\Default 1>>C:\tmp\3.txt
echo C:\tmp\profiles.ini !WSProfile!\AppData\Roaming\Mozilla\Firefox 1>>C:\tmp\4.txt
)
)
) ELSE (
echo !HomeProfile!\FireFoxProfile\Default 1>>C:\tmp\5.txt
FOR / %B IN (!HomeProfile!.V2) DO (
SET "WSProfile=%B"
FOR /F "usebackq delims" %C IN ('DIR /S /B /O:-D !WSProfile!\AppData\Roaming\Mozilla\Firefox\Profiles\places.sqlite') DO (
SET "FFProfile=%C"
echo !FFProfile! home\!HomeProfile!\FireFoxProfile\Default 1>>C:\tmp\6.txt
echo C:\tmp\profiles.ini !WSProfile!\AppData\Roaming\Mozilla\Firefox 1>>C:\tmp\7.txt
)
)
)
)
V:\home>(
SET "WSProfile=testuser1.V2"
FOR /F "usebackq delims" %C IN ('DIR /S /B /O:-D !WSProfile!\AppData\Roaming\Mozilla\Firefox\Profiles\places.sqlite') DO (
SET "FFProfile=%C"
echo !FFProfile! home\!HomeProfile!\FireFoxProfile\Default 1>>C:\tmp\3.txt
echo C:\tmp\profiles.ini !WSProfile!\AppData\Roaming\Mozilla\Firefox 1>>C:\tmp\4.txt
)
)
V:\home>(
SET "FFProfile=DIR"
echo !FFProfile! home\!HomeProfile!\FireFoxProfile\Default 1>>C:\tmp\3.txt
echo C:\tmp\profiles.ini !WSProfile!\AppData\Roaming\Mozilla\Firefox 1>>C:\tmp\4.txt
)
What caught my eye starts at these lines:
cd profile_WS
FOR / %B in (!HomeProfile!.V2) DO (
SET "WSProfile=%B"
FOR / %Bis a problem. What do you see in the console output where the wrong output is produced? - lit*.defaultpath. Also are you aware that the actual paths to their profile directories are written in file in a known location? You can just retrieve/parse them from there. - Compo