【问题标题】:Creating set of folders inside some folders using CMD使用 CMD 在某些文件夹中创建一组文件夹
【发布时间】:2016-02-10 19:20:34
【问题描述】:

我正计划创建某种档案。 假设我有这些文件夹 a = {A, B, C, D} 我还有另一个文件夹集合,例如 b = {1, 2, 3, 4}

现在,我如何使用 .bat 文件创建文件夹,以便“a”中的每个文件夹都有“b”文件夹。这意味着“a”中的每个文件夹都应该有“1、2、3、4”作为子文件夹。

我尝试使用 xcopy 做某事,但没有成功。

【问题讨论】:

    标签: windows batch-file cmd directory


    【解决方案1】:

    这适用于我在 Windows 7 上:

    for %%a in (A,B,C,D) do (
        for %%i in (1,2,3,4) do (
           mkdir  %%a\\%%i
        )
    )  
    

    回答您关于更通用脚本的问题;把它放到一个批处理文件中,比如a.bat 并运行它。

    @echo off
    rem the directory where I wish to make subdirectories
    set mypath=C:\Users\Philip\AppData\Local\Temp\Test
    
    rem go to that directory
    cd /d %mypath%
    
    rem the names of subdirectories I want to create for each directory (no outer quotes)
    set mydirs=ralph,john,sally,betty,11,22
    
    for /f %%a in ('dir/b/ad') do (
        for %%i in (%mydirs%) do (
            if not exist %%a\\%%i (
                mkdir %%a\\%%i 
            )
        )
    )  
    

    如果您只需要目录的子集,您可以将外部 for 更改为使用通配符。例如。仅以C 开头的目录

    for /f %%a in ('dir/b/ad C*') do (
    

    【讨论】:

    • 效果很好!谢谢你!但我还有一个问题,有没有办法不指定 A、B、C、D?喜欢使用星号 (*) 吗?
    猜你喜欢
    • 2022-01-11
    • 2015-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-25
    • 1970-01-01
    • 2018-12-02
    • 2021-02-15
    相关资源
    最近更新 更多