gpt4 book ai didi

powershell - 创建子目录/子文件夹

转载 作者:行者123 更新时间:2023-12-04 13:02:18 26 4
gpt4 key购买 nike

我正在创建一个 PowerShell 脚本来“编译”散布在我的笔记中的一堆文档。我想先创建目录结构,然后将文件复制到新创建的目录中。我知道如何手动执行此操作,但我不确定如何在 PowerShell 中进行处理。虽然我确实了解几种不同语言的编程,但我一般不熟悉脚本。

我应该更改当前目录,然后再创建一些目录吗?或者有不同的方法吗?

这是我到目前为止:

#Variables
$containerFolder = "F:\FSG\Packet.Fusion for IT and AV Professionals"
$rootFolder = "Fusion for IT and AV pros $(Get-Date -format “MM-dd-yyyy”)"


#create the directory structure
md -Path $containerFolder -Name $rootFolder

我想在 $rootFolder 中创建几个目录,其中 1 或 2 个将有自己的子目录。如果我在命令行中执行此操作,我会 cd 到新目录,然后再 md 一些。这是如何用脚本来做到这一点?

编辑 这就是我开始的内容:
# Compiles the Fusion packet for distribution

###############################
###########Variables###########
###############################

#folder structure
$FSG = "F:\FSG"
$containerFolder = "Packet.Fusion for IT and AV Professionals"
$rootFolder = "Fusion for IT and AV pros $(Get-Date -format “MM-dd-yyyy”)"
$subRoot1 = "Fusion Server"
$subRoot2 = "Scheduling Enhancement and Panels"
$subRoot2sub1 = "Scheduling Panels"
$subRoot3 = "SQL Server"

#source folders
$HW = "0.Hardware"
$3SMDoc = "0.Hardware\TPMC-3SM.Documentation"
$4SMDoc = "0.Hardware\TPMC-4SM.Documentation"
$4SMDDoc = "0.Hardware\TPMC-4SM-FD.Documentation"
$730Doc = "0.Hardware\TSW-730.Documentation"
$730OLH = "0.Hardware\TSW-730.OLH"
$CENRVS = "0.Hardware\CEN-RVS.Notes"

$ProjMgmt = "0.Project Management"

$SW = "0.Software"
$RVLicensing = "0.Software\0.RoomView.License"
$RVNotes = "0.Software\0.RoomView.Notes"
$SQLLicensing = "0.Software\database.SQL.Licensing"
$SQLNotes = "0.Software\database.SQL.Notes"
$FRVMarketing = "0.Software\Fusion RV.Marketing"
$FRVNetworking = "0.Software\Fusion RV.Networking"
$FRVNotes = "0.Software\Fusion RV.Notes"


###############################
#create the directory structure
###############################

md -Path $containerFolder -Name $rootFolder

cd $FSG\$containerFolder\$rootFolder
md "eControl and xPanels"
md "Fusion Server" #$subRoot1
md "Getting Started as a User"
md "Project Management"
md "RoomView Connected Displays"
md "Scheduling Enhancement and Panels" #$subRoot2
md "SQL Server" #$subRoot3

cd $FSG\$containerFolder\$rootFolder\$subRoot1
md "CEN-RVS"
md "Licenseing Information"
md "Networking"
md "Official Documentation"
md "Prerequisites, including powerShell script"
md "Product Info"
md "Requirements"
md "Tech Info"
md "Windows Authentication to Fusion RV"

cd $FSG\$containerFolder\$rootFolder\$subRoot2
md "Outlook Add-in"
md "Scheduling Panels" #$subRoot2sub1

cd $FSG\$containerFolder\$rootFolder\$subRoot2\$subRoot2sub1
md "TPMC-3SM"
md "TPMC-4SM"
md "TPMC-4SM-FD"
md "TSW-730"

cd $FSG\$containerFolder\$rootFolder\$subRoot3
md "Multi-database model only"
md "SQL Licensing"

创建叶最多的子目录并暗示让 PowerShell 创建中间的子目录有什么好处吗?

这样做有什么缺点吗?

最佳答案

New-Item -ItemType Directory -Path C:\NewPath\NewSubPath\AnotherSubDir\WowThisIsReallyNested -Force

这将创建完整路径,包括所有子目录。

关于powershell - 创建子目录/子文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20982765/

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