找出是否存在整个文件夹结构(CMD Batch)

时间:2013-06-29 15:19:04

标签: windows command-line batch-file directory cmd

我觉得这应该很容易做到,但我自己也无法弄明白。 也许有人能够提供帮助。

我有这个小的批处理脚本,它基本上检查文件夹Folder1是否已经存在。如果没有,则会创建Folder1Folder6。如果是这样,它将简单地回应这一事实。

@ECHO OFF
If not exist Folder1 (for /L %%a in (1,1,6) do md Folder%%a) else (ECHO Folder structure already exists)

我现在要做的是将If not exist Folder1替换为更有意义的东西。 I. e。 If not exist folder with any string greater or equal to 'Folder'

我会这样做吗?

3 个答案:

答案 0 :(得分:2)

岂不

for /L %%a in (1,1,6) do md Folder%%a

更容易,并创建目录,无论它们是否已经存在?

for /L %%a in (1,1,6) do md Folder%%a 2>nul

应该禁止现有目录的消息。

答案 1 :(得分:1)

这可能适合你:

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
    )
)

答案 2 :(得分:0)

@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
)