【发布时间】:2016-05-24 10:49:20
【问题描述】:
我正在尝试在某个目标位置创建目录,如果它们不存在的话。
目录的名称来自另一个源位置。
对于C:\some\location中的每个目录名称
在C:\another\location.新建同名目录
例如。
c:\some\location\
\apples
\oranges
to
c:\another\location\
\apples
\oranges
所以实际上我正在从source -> to -> target 重新创建所有文件夹。
不是递归的,顺便说一句。只是顶层。
所以到目前为止,我已经通过 PS:
dir -Directory | New-Item -ItemType Directory -Path (Join-Path "C:\jussy-test\" Select-Object Name)
或
dir -Directory | New-Item -ItemType Directory -Path "C:\new-target-location\" + Select-Object Name
我被困住了。我正在努力纠正最后一点。但无论如何,也许有人脑子里有更好的主意?
【问题讨论】:
-
单行:
dir -Path C:\some\location\* -Directory | % { New-Item -ItemType Directory -Path C:\another\location\ -Name $_.Name }
标签: powershell