if statement - Go Back to Start If no input is entered (Bat File) (#2) -


this follow-up question: go start if no input entered (bat file) final touch , file perfect :) here's relevant code part:

:: delete variable %f% set "f=" set /p f=folder or file trget: attrib +s +h +r %f% 

if set non input, file makes relevant files in same folder , same extension (as in attrib +s +h +r *.bat) ,(in case, bat) in system files

i apologize bad wording

the complete procedure of script (it's not script onlly on part of it)

:hide @echo off cls color 0c  echo. echo. :: delete variable %f% set "f=" set /p f=folder or file trget: attrib +s +h +r %f%   @echo off cls echo. echo. echo   ###################################################### echo   #                                                    # echo   # 1 - set other system attribute folder or file # echo   # 2 - remove system attribute folder or file  # echo   # 3 - exit                                           # echo   #                                                    # echo   ###################################################### echo. echo.  :: delete variable %a% set "a=" set /p a=set choice , press enter:  echo loading .........  if "%a%"=="1" goto hide if "%a%"=="2" goto show if "%a%"=="3" goto exit  goto hide 

  1. always take filename quotes becouse can have spaces.
  2. delete quotes filename. more: set /?

    set f=%f:"=% 
    1. make sure input not empty. command 'if not "%f%"==""' - checks input isn't empty. command 'if exist "%f%"' checks file exist.

      :: delete variable %f% set "f=" set /p f=folder or file target: set f=%f:"=%  if not "%f%"=="" if exist "%f%" attrib +s +h +r "%f%" 
    2. if have many commands can't runned without input can add procedure in end of file , call it

      if not "%f%"=="" if exist "%f%" call :hidechecked  :: there code. remember, call :label returns & keeps batch execution. read more: call /? :: there code ends. , new procedure starts.  :: prevent crazy parsing exit /b  :hidechecked     attrib +s +h +r %f% :: exit /b == return exit /b 
  3. always user, error

    if not "%f%"=="" if exist "%f%" call :hidechecked  if "%f%"=="" (     echo must choose     rem in 'if ()' can use rem comments.     rem >nul - means command 'pause' print nothing (except errors)     pause>nul     goto hide ) if not exist "%f%" (     echo no such file. file list:     rem dir /?     dir /p/b     pause>nul     goto hide ) 
  4. in start of file add 'goto input'. after each procedure (:hide :show :exit) add 'goto input' prevent crazy parsing.

    :: @ start of file goto input  :: there can code  :show     :: , there goto input  :hide     @echo off     cls     color 0c      echo.     echo.     :: delete variable %f%     set "f="     set /p f=folder or file target:         set f=%f:"=%      if not "%f%"=="" if exist "%f%" call :hidechecked     if "%f%"=="" (         echo must choose         rem in 'if ()' can use rem comments.         rem >nul - means command 'pause' print nothing (except errors)         pause>nul         goto hide     )     if not exist "%f%" (         echo no such file. file list:         rem dir /?         dir /p/b         pause>nul         goto hide     )  goto input  :input                     @echo off     cls     echo.     echo.     echo   ######################################################     echo   #                                                    #     echo   # 1 - set other system attribute folder or file #     echo   # 2 - remove system attribute folder or file  #     echo   # 3 - exit                                           #     echo   #                                                    #     echo   ######################################################     echo.     echo.      :: delete variable %a%     set "a="     set /p a=set choice , press enter:       if "%a%"=="1" goto hide     if "%a%"=="2" goto show     if "%a%"=="3" goto exit      echo must choose     pause>nul      goto input  :: prevent crazy parsing exit /b  :hidechecked     attrib +s +h +r "%f%" :: exit /b == return exit /b 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -