Reputation: 31
I feel like this should be easy to do, but can't quite figure it out on my own. Perhaps someone is able to help.
I have this tiny batch script that basically checks whether a folder Folder1
already exists or not. If it doesn't, it will create Folder1
to Folder6
. If it does, it will simply echo this fact.
@ECHO OFF
If not exist Folder1 (for /L %%a in (1,1,6) do md Folder%%a) else (ECHO Folder structure already exists)
What I want to do now is replace the If not exist Folder1
with something that makes a tad more sense. I. e. If not exist folder with any string greater or equal to 'Folder'
Any way I would do this?
Upvotes: 3
Views: 255
Reputation: 41224
@echo off
set "flag="
for /L %%a in (1,1,6) do if not exist "Folder%%a\" set flag=1
if defined flag (
echo at least one of your folders is missing captain.
for /L %%a in (1,1,6) do md Folder%%a 2>nul
) else (
echo Warp speed, no folders to create
)
Upvotes: 0
Reputation: 37569
this might work for you:
rem if not exist folder if not exist "folder1" ( rem with any string greater or equal to 'Folder' if "folder1" geq "Folder" ( rem do sth. rem do sth. more ) )
Upvotes: 1
Reputation: 79982
Wouldn't
for /L %%a in (1,1,6) do md Folder%%a
be easier, and create the directories whether or not they already exist?
for /L %%a in (1,1,6) do md Folder%%a 2>nul
should suppress messages for already-existing directories.
Upvotes: 2