I’m trying to convert the following unix shell script to windows:
for strWorkerDirectory in $BASEDIR/worker01/applogs $BASEDIR/worker01/filtered $BASEDIR/worker01/filtered/error-logs $BASEDIR/worker01/filtered/logs $BASEDIR/worker01/filtered/session-logs
do
if [ ! -d $strWorkerDirectory ]; then
mkdir -p $strWorkerDirectory
fi
done
So far, I came up with this:
FOR %%strWorkerDirectory IN (%BASEDIR%worker01\applogs %BASEDIR%worker01\filtered %BASEDIR%worker01\filtered\error-logs %BASEDIR%worker01\filtered\logs %BASEDIR%worker01\filtered\session-logs) DO
(
IF exist %%strWorkerDirectory ( echo %%strWorkerDirectory exists ) ELSE ( mkdir %%strWorkerDirectory && echo %%strWorkerDirectory created)
)
but i’m getting an error message which just says something is wrong here
"%strWorkerDirectory" kann syntaktisch an dieser Stelle nicht verarbeitet werden.
What would be the correct conversion here?
Two issues:
%%sfor example.Note that depending on the type of the
FORloop the names have a meaning (seeFOR /?for more information); for example when used with `FOR /F “tokens=…”“. In your case it shouldn’t matter though.DOComplete example:
Hint: you can use a caret (
^) as line continuation character to avoid overly long lines. Just make sure there is really no other character (not even whitespace) after the caret.EDIT As commenter @dbenham points out, the line continuation inside above are not actually neccessary.