Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting a variable within batch file not working

Status
Not open for further replies.

jdeane

IS-IT--Management
Sep 21, 2001
229
GB
hi

I'm trying to delete Firefox's cache for individual users, as the Firefox profile is uniquely named for each user it is not just a case of deleting a folder or on Win XP Firefox won't start, so having to remove the cache folder within the profile folder
i.e.
C:\Documents and Settings\admin\Local Settings\Application Data\Mozilla\Firefox\Profiles\afocurwn.Default User\Cache

the batch file is:-
:mad:echo off
cls
:kill browsers
taskkill /im firefox.exe /f
taskkill /im chrome.exe /f
:wait for 2 seconds
PING 127.0.0.1 -n 3 > nul
if exist "C:\users\" (
:Vista and above
echo Vista and above:-
echo.
if exist "C:\Users\%USERNAME%\AppData\Local\Mozilla\Firefox\" rd /s /q "C:\Users\%USERNAME%\AppData\Local\Mozilla\Firefox\Profiles"
if exist "C:\Users\%USERNAME%\AppData\Local\Google\Chrome\" rd /s /q "C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data"
) else (
:Windows XP
Echo Windows XP
echo.
SET profile=
PUSHD "%UserProfile%\Application Data\Mozilla\Firefox"
FOR /F "tokens=2 delims==" %%A IN ('TYPE profiles.ini ^| FINDSTR.EXE /R /B /I /C:"Path="') DO SET profiles="%%~nxA"
POPD
PING 127.0.0.1 -n 5 > nul
Echo Profile name is '%profiles%'
pause

Echo %UserProfile%\Local Settings\Application Data\Mozilla\Firefox\Profiles\%Profile%\cache
if exist "%UserProfile%\Local Settings\Application Data\Mozilla\Firefox\Profiles\%Profile%\cache" RD /Q /S "%UserProfile%\Local Settings\Application Data\Mozilla\Firefox\Profiles\%Profile%\cache"
pause
echo %UserProfile%\Local Settings\Application Data\Mozilla\Firefox\Profiles\%Profile%\Cache.Trash
if exist "%UserProfile%\Local Settings\Application Data\Mozilla\Firefox\Profiles\%Profile%\cache.trash" RD /Q /S "%UserProfile%\Local Settings\Application Data\Mozilla\Firefox\Profiles\%Profile%\Cache.Trash"
pause
echo %UserProfile%\Local Settings\Application Data\Mozilla\Firefox\Profiles\%Profile%\OfflineCache
if exist "%UserProfile%\Local Settings\Application Data\Mozilla\Firefox\Profiles\%Profile%\OfflineCache" RD /Q /S "%UserProfile%\Local Settings\Application Data\Mozilla\Firefox\Profiles\%Profile%\OfflineCache"

PING 127.0.0.1 -n 3 > nul

if exist "%userprofile%\Local settings\application data\Google\Chrome\" rd /s /q "%userprofile%\Local settings\application data\Google\Chrome\user data"
)
:end
Echo Finished...
pause



now when the batch file is ran from an open command prompt window the first time is shows the following (first part of output removed to only show the problem)

-----
Windows XP


C:\Documents and Settings\admin\Application Data\Mozilla\Firefox>SET profiles="afocurwn.Default User"
Profile name is ''
-----

If the command prompt is left open and the batch file ran again it will work correctly, or at the end of running the batch file originally I type echo %profiles% it displays the correct result.

it appears that it is only the first time that the batch file is ran that it fails, the issue is that I need it to run first time as the link to run this will be on a web page so the DOS window will open and close when it is ran so there is no option 're-run' from the same window.

any ideas before I completely loose the plot??

Jon
 
never mind I fixed it this morning with a fresh look at it and corrected the 'deliberate' mistake...

Jon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top