gpt4 book ai didi

powershell - 如何使用 Powershell 创建文件夹结构骨架?

转载 作者:行者123 更新时间:2023-12-04 23:26:58 24 4
gpt4 key购买 nike

我们的应用程序有文件夹/子文件夹结构。

每当我们添加新模块时,我们必须完全复制文件夹结构而不复制文件。

如何复制层次结构中的文件夹和子文件夹但不保留文件?

最佳答案

这有点“hacky”,因为 Powershell 不能很好地处理这个问题……公认的智慧说使用 xCopy 或 Robocopy 但如果你真的需要使用 Powershell,这似乎可以正常工作:

$src = 'c:\temp\test\'
$dest = 'c:\temp\test2\'

$dirs = Get-ChildItem $src -recurse | where {$_.PSIsContainer}

foreach ($dir in $dirs)
{
$target = ($dir.Fullname -replace [regex]::Escape($src), $dest)

if (!(test-path $target))
{
New-Item -itemtype "Directory" $target -force
}
}

关于powershell - 如何使用 Powershell 创建文件夹结构骨架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11343613/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com