![](/img/trans.png)
[英]Export sub-folder name as path and create a csv for each parent sub-folder in a different location
[英]What is a code to create a sub-folder in each folder and then move all the files and folders into that sub-folder?
我正在為客戶組織所有文檔,其結構應如下所示: Customer Service\\Customer\\"Customer's Name"\\Quotation
。
到目前為止,我設法在每個客戶的文件夾中創建“報價”文件夾。
foreach ($folder in (Get-ChildItem 'C:\Users\S7051895\Desktop\Customer Service\Customer' -Directory)) {
New-Item -ItemType Directory -Path ($folder.FullName + "\Quotes")
}
我已經在所有客戶的文件夾中創建了Quotes子文件夾。 現在,我需要將所有文件和文件夾從客戶的文件夾移到Quotes子文件夾中。 我想理想地在一個腳本中完成它。 雖然,任何事情都會很棒,因為有數百個客戶。
foreach ($folder in (Get-ChildItem 'C:\Users\S7051895\Desktop\Customer Service\Customer' -Directory))
{
$files = Get-ChildItem $folder.FullName
$newfolder = new-item -ItemType directory -Path ($folder.fullname+"\Quotes")
$files | Move-Item -Destination $newfolder.FullName
}
在創建“ Quotes”文件夾之前,您可以獲取文件夾中所有文件的列表。
由於您已經具有創建子文件夾的代碼,因此只需將文件夾內容移動到新的子文件夾即可。
$dir = 'C:\Users\S7051895\Desktop\Customer Service\Customer'
$quotes = 'Quotes'
foreach ($folder in (Get-ChildItem $dir -Directory)) {
$newdir = Join-Path $folder.FullName $quotes
New-Item -ItemType Directory -Path $newdir | Out-Null
Get-ChildItem $folder.FullName -Exclude $quotes |
Move-Item -Destination $newdir
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.