Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Powershell在文件夹中循环,创建一个名为“的文件夹”;测试“;各_Powershell_Loops_Foreach - Fatal编程技术网

使用Powershell在文件夹中循环,创建一个名为“的文件夹”;测试“;各

使用Powershell在文件夹中循环,创建一个名为“的文件夹”;测试“;各,powershell,loops,foreach,Powershell,Loops,Foreach,如何循环遍历文件夹,并在每个文件夹中创建文件夹“test”。然后将整个子文件夹结构移到其中 首先,结构如下所示: ├─Folder1 │ ├─Subfolder1 │ └─Subfolder2 └─Folder2 ├─Subfolder1 └─Subfolder2 $folders = Get-ChildItem U:\AsBuiltKopieScript\Kopie10StandorteCD1\* -Directory; foreach ($Folder in $Folders) {

如何循环遍历文件夹,并在每个文件夹中创建文件夹“test”。然后将整个子文件夹结构移到其中

首先,结构如下所示:

├─Folder1 │ ├─Subfolder1 │ └─Subfolder2 └─Folder2 ├─Subfolder1 └─Subfolder2
$folders = Get-ChildItem U:\AsBuiltKopieScript\Kopie10StandorteCD1\* -Directory;
foreach ($Folder in $Folders) {
  $folder = New-Item -Type Directory -Path "U:\AsBuiltKopieScript\Kopie10StandorteCD1\#Folder.Fullname\GebäudeMast"
  Move-Item #Folder.Fullname -Destination 
}

但是它不起作用。

您的问题是,当您选择目标路径时,请尝试以下方法

$Root="U:\AsBuiltKopieScript\Kopie10StandorteCD1"

Get-ChildItem "C:\Temp\root" -directory | %{
$NewItem=New-Item -Path "$($_.FullName)\test" -ItemType Directory -Force
Get-ChildItem $_.FullName | where fullname -ne $NewItem.FullName | Move-Item -Destination $NewItem.FullName
}
试试这个-

Get-ChildItem U:\AsBuiltKopieScript\Kopie10StandorteCD1\ -Directory -recurse | % { New-Item -type directory -path "$($_.FullName)" -Name "test"}

多谢各位。简短的问题,我是Powershell新手,但%是否作为foreach命令的别名存在?是的,确切地说:)
Get-ChildItem U:\AsBuiltKopieScript\Kopie10StandorteCD1\ -Directory -recurse | % { New-Item -type directory -path "$($_.FullName)" -Name "test"}