mkdir x 级别下降
mkdir x levels down
我有一个包含多个州合同的文件夹,每个州文件夹都有多个合同:
D:\Workspace\Contracts\State1\Contract1_number_date
D:\Workspace\Contracts\State1\Contract2_number_date
D:\Workspace\Contracts\State2\Contract1_number_date`
etc...
我需要为每个合同制作3个文件夹:
D:\Workspace\Contracts\State1\Contract1_number_date\folder1
D:\Workspace\Contracts\State1\Contract1_number_date\folder2
D:\Workspace\Contracts\State1\Contract1_number_date\folder3
D:\Workspace\Contracts\State1\Contract2_number_date\folder1
D:\Workspace\Contracts\State1\Contract2_number_date\folder2
D:\Workspace\Contracts\State1\Contract2_number_date\folder3
D:\Workspace\Contracts\State2\Contract1_number_date\folder1
D:\Workspace\Contracts\State2\Contract1_number_date\folder2
D:\Workspace\Contracts\State2\Contract1_number_date\folder3
我发现 \..\
向上一级,所以 mkdir D:\Workspace\Contracts\..\folder1
使 D:\Workspace\folder1
,但我不知道如何向下一级或 10 个文件夹。
下面是一些使用 For
循环实现您的目标的代码:
@Echo Off
Set "BaseDir=%~1"
Set "NumStates=%~2"
Set "NumContracts=%~3"
Set "NumFolders=%~4"
If Not Exist "%BaseDir%\" Exit/B
For %%A In (NumStates NumContracts NumFolders) Do If Not Defined %%A Exit/B
If /I Not "%CD%"=="%BaseDir%" CD /D "%BaseDir%"
For /L %%A In (1,1,%NumStates%) Do For /L %%B In (1,1,%NumContracts%
) Do For /L %%C In (1,1,%NumFolders%
) Do If Not Exist "State%%A\Contract%%B_number_date\folder%%C\" (
MD "State%%A\Contract%%B_number_date\folder%%C")
您可以从命令行 运行 您的脚本,命名为 MakeDirs.cmd
:
"MakeDirs.cmd" "D:\Workspace\Contracts" 17 8 3
上面应该为 8
合同和 17
州在 D:\Workspace\Contracts
.
中创建 3
目录
我有一个包含多个州合同的文件夹,每个州文件夹都有多个合同:
D:\Workspace\Contracts\State1\Contract1_number_date
D:\Workspace\Contracts\State1\Contract2_number_date
D:\Workspace\Contracts\State2\Contract1_number_date`
etc...
我需要为每个合同制作3个文件夹:
D:\Workspace\Contracts\State1\Contract1_number_date\folder1
D:\Workspace\Contracts\State1\Contract1_number_date\folder2
D:\Workspace\Contracts\State1\Contract1_number_date\folder3
D:\Workspace\Contracts\State1\Contract2_number_date\folder1
D:\Workspace\Contracts\State1\Contract2_number_date\folder2
D:\Workspace\Contracts\State1\Contract2_number_date\folder3
D:\Workspace\Contracts\State2\Contract1_number_date\folder1
D:\Workspace\Contracts\State2\Contract1_number_date\folder2
D:\Workspace\Contracts\State2\Contract1_number_date\folder3
我发现 \..\
向上一级,所以 mkdir D:\Workspace\Contracts\..\folder1
使 D:\Workspace\folder1
,但我不知道如何向下一级或 10 个文件夹。
下面是一些使用 For
循环实现您的目标的代码:
@Echo Off
Set "BaseDir=%~1"
Set "NumStates=%~2"
Set "NumContracts=%~3"
Set "NumFolders=%~4"
If Not Exist "%BaseDir%\" Exit/B
For %%A In (NumStates NumContracts NumFolders) Do If Not Defined %%A Exit/B
If /I Not "%CD%"=="%BaseDir%" CD /D "%BaseDir%"
For /L %%A In (1,1,%NumStates%) Do For /L %%B In (1,1,%NumContracts%
) Do For /L %%C In (1,1,%NumFolders%
) Do If Not Exist "State%%A\Contract%%B_number_date\folder%%C\" (
MD "State%%A\Contract%%B_number_date\folder%%C")
您可以从命令行 运行 您的脚本,命名为 MakeDirs.cmd
:
"MakeDirs.cmd" "D:\Workspace\Contracts" 17 8 3
上面应该为 8
合同和 17
州在 D:\Workspace\Contracts
.
3
目录