Created
March 28, 2017 04:04
-
-
Save KiT106/d61352f28cab28b98cb2fcf710b6ec8b to your computer and use it in GitHub Desktop.
Check directory in Windows batch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
echo %~1 | |
::::::::::::::::::: has argument ? ::::::::::::::::::: | |
IF ["%~1"]==[""] ( | |
echo Missing argument!!! | |
echo Syntax: | |
echo setup ^<main_repo^> | |
exit /B 1; | |
) | |
::::::::::::::::::: argument exist ? ::::::::::::::::::: | |
IF NOT EXIST %~s1 ( | |
echo "%~1" not exist | |
exit /B 1 | |
) | |
::::::::::::::::::: is directory ? ::::::::::::::::::: | |
IF NOT EXIST %~s1\NUL ( | |
echo "%~1" is a file. Require directory! | |
exit /B 1 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
%~1
- the~
removes any wrapping"
or'
.%~s1
- the s makes the path beDOS 8.3 naming
, which is a nice trick to avoid spaces in file-name while checking stuff (and this way no need to wrap the resource with more"
s.["%~1"]==[""]
"can not be sure" if the argument is a file/directory or just a generic string yet, so instead the expression uses brackets and the original unmodified%1
(just without the"
wrapping, if any..)if there were no arguments of if we've used
shift
and the arg-list pointer has passed the last one, the expression will be evaluated to[""]==[""]
.Source