【发布时间】:2022-01-21 16:03:20
【问题描述】:
我需要创建一个名称从 E1 到 E10 的文件夹和子文件夹,并且每个文件夹内还有 10 个文件夹,我如何在 PowerShell ISE 中执行此操作?
【问题讨论】:
标签: powershell scripting nested subdirectory
我需要创建一个名称从 E1 到 E10 的文件夹和子文件夹,并且每个文件夹内还有 10 个文件夹,我如何在 PowerShell ISE 中执行此操作?
【问题讨论】:
标签: powershell scripting nested subdirectory
以下创建子文件夹 E1 到 E10,并在每个子文件夹中创建子文件夹 F1 到 F10:
# Creates subdirectories and returns info objects about them.
# -Force means that no error is reported for preexisting subdirs.
# Use $null = New-Item ... to suppress output.
New-Item -Type Directory -Force `
-Path (1..10 -replace '^', 'E').ForEach({ 1..10 -replace '^', "$_\F" })
注意:
-replace '^', '...' 是一种将文本添加到每个输入数组元素(在本例中为使用..、range operator 创建的每个序列号)的简单方法。李>
-replace '$', '...' 将追加。^.*匹配整个输入,$&在替换文本中引用它;例如-replace '^.*', 'Before-$&-After'
【讨论】: