我打算创建某种存档。 假设我有这些文件夹a = {A,B,C,D} 我有另一个文件夹集合,如b = {1,2,3,4}
现在,我如何使用.bat文件创建文件夹,以便“a”中的每个文件夹都有“b”文件夹。这意味着“a”中的每个文件夹都应该有“1,2,3,4”作为子文件夹。
我尝试使用xcopy做一些事情,但它不起作用。
答案 0 :(得分:2)
这适用于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 (