Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

setting a variable within batch file not working

setting a variable within batch file not working

setting a variable within batch file not working


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
C:\Documents and Settings\admin\Local Settings\Application Data\Mozilla\Firefox\Profiles\afocurwn.Default User\Cache

the batch file is:-
:@echo off
:kill browsers
taskkill /im firefox.exe /f
taskkill /im chrome.exe /f
:wait for 2 seconds
PING -n 3 > nul
if exist "C:\users\" (
:Vista and above
echo Vista and above:-
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
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"
PING -n 5 > nul
Echo Profile name is '%profiles%'

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"
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"
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 -n 3 > nul

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

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??


RE: setting a variable within batch file not working

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


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close