issue with rd cmd in a batch file

Discussion in 'Software' started by red death68, Jan 27, 2011.

  1. red death68

    red death68 Command Sergeant Major

    ok so basicly i made a batch file to automate some basic system mainenance the problem is i cant get it to clean up after its self.

    i am packaging it in and sfx archive using winrar the problem is that i want it to remove the folder it was extracted to after running for easy clean up but it will either not work all together or it will just delete the files and leave the directory saying its in use any suggestions? here is the code so far

    Code:
    @echo off
    
    echo                        Welcome to the automated maintenance 
    echo.   
    echo   This file will only work properly on an account with administrative privliges
    @ping 127.0.0.1 -i 8 >nul
    cls
    
    :start
    echo What maintenance would you like to run on this system?
    echo.   
    echo [d] defragment a system drive
    echo [c] check disc for consistency
    echo [r] clean RAM to increase system performance
    echo [e] exit
    
    >nul set /p "answer=what maintenance would you like to run on this system? [c/d/a/] "
    if /i "%answer%" == "c" goto :check disk
    if /i "%answer%" == "d" goto :defrag
    if /i "%answer%" == "a" goto :anti-virus
    if /i "%answer%" == "r" goto :ram
    if /i "%answer%" == "e" goto :end
    echo invalid choice
    goto :start
    
    :check disc
    cls
    echo What would you like to do?
    echo. 
    echo [r] retrive redable data from damaged sectors
    echo [f] fix errors found on disk
    echo [e] exit
    
    >nul set /p "answer=would like to run chkdsk? "
    if /i "%answer%" == "r" goto :repair
    if /i "%answer%" == "f" goto :fix
    if /i "%answer%" == "e" goto eof
    echo invalid option
    goto :check disc
    
    
    :fix
    chkdsk /f
    goto :end
    
    :repair
    chkdsk /r
    goto :end
    
    
    :defrag
    cls
    echo What disk drive would you like to defragment?
    echo.
    >nul set /p "answer=What disk drive would you like to defragment? "
    echo --------------------------------------------------------------------------------
    echo your choice is %answer% is this correct? [y/n]
    >nul set /p "answer2=see if this is correct drive. "
    if /i "%answer2%" == "y" goto :run
    if /i "%answer2%" == "n" goto :defrag
    echo Invalid option
    goto :defrag
    
    :run
    defrag %answer%:
    goto :end
    
    :ram
    cls
    echo Are you sure you want to do this? [y/n]
    >nul set /p "answer=Are you sure? "
    if /i "%answer%" == "y" goto :run2
    if /i "%answer%" == "n" goto :end
    echi invalid option
    goto :ram
    
    
    :run2
    >nul start /wait "clean ram.vbs" "C:/temp/clean ram.vbs"
    echo proccess complete press any key to exit.
    >nul pause
    
    
    :end
    start cmd.exe /c rd /s /q c:\temp
    exit
     
  2. PC-XT

    PC-XT Master Sergeant

    I'm thinking it won't delete the working directory. Try
    cd ..
    or
    cd \
    before removing the extracted directory.
     
  3. red death68

    red death68 Command Sergeant Major

    worked perfectly once i alterd the end cmd a bit changed it to c:\ as the directory and then ran remove cmd without initating another cmd window


    so thank you very very much it worked perfectly and sorry for late reply since it was a side project i hadnt had time to repackage it and try
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds