needing help with an if command

Hewlett-packard 5700
September 15, 2009 at 12:32:35
Specs: Windows XP, ???
Hey all, need help with an if command. I am creating a simple script (yeah simple lol) that deletes temp files, cookies and normal junk. I have created an if that prompts you to delete files from your user id or to delete from another. that part works great. Actually both parts work great. its when I type in a profile that does not exist that I have a problem. When I type in a profile that does not exist everything in the folder where the script file is located is deleted, even the batch file itself. what I want to do is perform a dir of the docume~1 folder save it to a file and then compare the users inaput to that file. If the name does not exist the programs returns a message that the user id is not valid and starts over.

See More: needing help with an if command

Report •


#1
September 15, 2009 at 12:36:46
Here is the code I have created.

@echo off

Echo ******************************************************************************
Echo Delete Tempory files to speed up the users computer
ECHO You will be prompted to use the current users profile or enter a new name
Echo Written by Steven Justice
ECHO ******************************************************************************


set /p prompt=Do you want to clean the current profile? (y or n)
ECHO %prompt%
if /i "%prompt%" == "y" goto current_userprofile


:user_assigned
set /p name= What is the profile name you want to clean?

c:

REM Del Quarantined SEP files
del C:\"Documents and Settings"\"All Users"\"Application Data"\Symantec\"Symantec Endpoint Protection"\Quarantine\*.* /f /q /s

rem del cookies
cd\docume~1\%name%\cookies\
del *.*/f /q /s

rem del windows temp files
cd %systemroot%\temp\
del *.* /f /q /s

rem del temp files
cd\docume~1\%name%\locals~1\temp
del *.* /f /q /s

rem del history
cd\docume~1\%name%\locals~1\history
del *.* /f /q /s

rem del temporary internet files
cd\docume~1\%name%\locals~1\tempor~1
del *.* /f /q /s

echo this is the user specific sub
pause

end


:current_userprofile

c:

REM Del Quarantined SEP files
del C:\"Documents and Settings"\"All Users"\"Application Data"\Symantec\"Symantec Endpoint Protection"\Quarantine\*.* /f /q /s

rem del cookies
cd\docume~1\%username%\cookies\
del *.*/f /q /s

rem del windows temp files
cd %systemroot%\temp\
del *.* /f /q /s

rem del temp files
cd\docume~1\%username%\locals~1\temp
del *.* /f /q /s

rem del history
cd\docume~1\%username%\locals~1\history
del *.* /f /q /s

rem del temporary internet files
cd\docume~1\%username%\locals~1\tempor~1
del *.* /f /q /s

echo this is the current user sub
pause


end


Report •

#2
September 15, 2009 at 23:04:19
@echo off & setLocal EnableDELAYedExpansion

set /p id=id ?

for /f "tokens=* delims= " %%a in ('dir/b/ad "C:\Documents and Settings"') do (
if /i "!id!" equ "%%a" goto :OK
)
echo !id! not found && goto :eof
:OK


=====================================
Helping others achieve escape felicity

M2


Report •

#3
September 16, 2009 at 06:59:23
Hey M2, That got it. Thanks a lot

I hate it when I am ready script forums and the final product is not posted. Here is the final product, I'm sure a more experienced programmer can clean it up some, but it gets the job done and saves the techs quite a bit of time
***********************************************************************
@echo off & setLocal EnableDELAYedExpansion

Echo ******************************************************************************
Echo Delete Tempory files to speed up the users computer
ECHO You will be prompted to use the current users profile or enter a new name
Echo Written by Steven Justice
ECHO ******************************************************************************

:begin
set /p prompt=Do you want to clean the current profile? (y or n)
if /i "%prompt%" == "y" goto current_userprofile

set /p name= What is the profile name you want to clean?

for /f "tokens=* delims= " %%a in ('dir/b/ad "C:\Documents and Settings"') do (
if /i "!name!" equ "%%a" goto :user_assigned
)

echo The profile !name! was not found
set /p newprompt=Do search again (y or n)
if /i "!newprompt!" == "y" goto begin
if /i "!newprompt!" == "n" goto end

:user_assigned

c:

REM Del Quarantined SEP files
del C:\"Documents and Settings"\"All Users"\"Application Data"\Symantec\"Symantec Endpoint Protection"\Quarantine\*.* /f /q /s

rem del cookies
cd\docume~1\%name%\cookies\
del *.*/f /q /s

rem del windows temp files
cd %systemroot%\temp\
del *.* /f /q /s

rem del temp files
cd\docume~1\%name%\locals~1\temp
del *.* /f /q /s

rem del temporary internet files
cd\docume~1\%name%\locals~1\tempor~1
del *.* /f /q /s

rem cpy and del history files
cd\docume~1\%name%\locals~1\history
if exist C:\Docume~1\%name%\Mydocu~1\history_backup\ goto historycopy
md C:\Docume~1\%name%\Mydocu~1\history_backup\
copy *.* C:\Docume~1\%name%\Mydocu~1\history_backup\ /y
del *.* /f /q /s

goto scriptend

:historycopy

copy *.* C:\Docume~1\%username%\Mydocu~1\history_backup\ /y
del *.* /f /q /s

goto scriptend


:current_userprofile

c:

REM Del Quarantined SEP files
del C:\"Documents and Settings"\"All Users"\"Application Data"\Symantec\"Symantec Endpoint Protection"\Quarantine\*.* /f /q /s

rem del cookies
cd\docume~1\%username%\cookies\
del *.*/f /q /s

rem del windows temp files
cd %systemroot%\temp\
del *.* /f /q /s

rem del temp files
cd\docume~1\%username%\locals~1\temp
del *.* /f /q /s

rem del temporary internet files
cd\docume~1\%username%\locals~1\tempor~1
del *.* /f /q /s

rem cpy and del history files
cd\docume~1\%username%\locals~1\history
if exist C:\Docume~1\%username%\Mydocu~1\history_backup\ goto historycopy
md C:\Docume~1\%username%\Mydocu~1\history_backup\
copy *.* C:\Docume~1\%userprofile%\Mydocu~1\history_backup\ /y
del *.* /f /q /s

goto scriptend

:historycopy

copy *.* C:\Docume~1\%username%\Mydocu~1\history_backup\ /y
del *.* /f /q /s

goto scriptend

:scriptend
Echo Script has finished successfully!
pause
cls
set /p endprompt=Are you finished cleaning this machine (y or n)
if /i "!endprompt!" == "n" goto begin
if /i "!endprompt!" == "y" goto applicationend
end

:applicationend
cls
Echo ******************************************************************************
Echo Script has finished successfully!
ECHO _________________________________
ECHO ******************************************************************************
pause
end

**********************************************************************


Report •

Related Solutions


Ask Question