gpt4 book ai didi

powershell - 在多个父文件夹中使用 PowerShell 创建子文件夹

转载 作者:行者123 更新时间:2023-12-05 02:23:00 25 4
gpt4 key购买 nike

我希望在网络共享的几个不同父文件夹中创建子文件夹。我有大约 900 个客户文件夹,我想在其中添加一个子文件夹。我在 Excel 电子表格(不是 CSV)中列出了客户,是否有创建这些子文件夹的简单方法?

New-Item -ItemType 目录 -Path "P:\Customer Folders\Customers A 到 D\

我正在使用上面的内容创建目录,但我不想使用这个命令 900 多次。 -recurse 似乎没有这样做,因为它给我一个错误。

如有任何帮助,我们将不胜感激。

最佳答案

好的,我在评论中给出代码时忘记了括号。以下是适合您的方法:

foreach($folder in (gci 'P:\customers a thru d' -directory)){
new-item -ItemType directory -Path ($folder.fullname+"\Helpdesk")
}

我创建了以下内容来进行测试:

C:\Temp\customers 通过 d\Microsoft
C:\Temp\customers a thru d\Starbucks
C:\Temp\customers a thru d\boeing

我运行了上面的代码(根据需要修改了路径),并按预期创建了文件夹。如果您想抑制输出,您可以将其通过管道传输到 |Out-Null,但这取决于您。

关于powershell - 在多个父文件夹中使用 PowerShell 创建子文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25980959/

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