Powershell 将文件从子文件夹复制到父文件夹,并使用父文件夹名称重命名该文件
我在桌面上有以下5个文件夹 每个文件夹都有一个子文件夹word,而word子文件夹包含文件document.xml。例如,这是文件的路径Powershell 将文件从子文件夹复制到父文件夹,并使用父文件夹名称重命名该文件,powershell,batch-file,Powershell,Batch File,我在桌面上有以下5个文件夹 每个文件夹都有一个子文件夹word,而word子文件夹包含文件document.xml。例如,这是文件的路径 (C:\Users\u0119342\Desktop\LEG_DOWNLOAD\BACK UP DOCX\document\Australian Citizenship (Transitionals and Consequentials) Act 2007\word\document.xml). 我想将document.xml从子文件夹word移到父文件夹
(C:\Users\u0119342\Desktop\LEG_DOWNLOAD\BACK UP DOCX\document\Australian Citizenship (Transitionals and Consequentials) Act 2007\word\document.xml).
我想将document.xml从子文件夹word移到父文件夹“2007年澳大利亚公民(过渡和后续)法案”
,并将其重命名为“2007年澳大利亚公民(过渡和后续)法案”
我希望对其余四个文件夹中的所有document.xml文件执行相同的过程
请告诉我是否有一种方法可以用powershell或批处理脚本来实现这一点
谢谢
文卡特我相信这会做好你的工作。试试看
$Root = "C:\Users\u0119342\Desktop\LEG_DOWNLOAD\BACK UP DOCX\document"
$Folders = Get-ChildItem -Path $Root
Foreach($Fld in $Folders)
{
If(Test-Path "$($Fld.FullName)\word\document.xml")
{
# Move the file document.xml and rename it
Move-Item -Path "$($Fld.FullName)\word\document.xml" -Destination "$($Fld.FullName)\$($Fld.Name).xml"
#Deletes Word folder
Remove-Item "$($Fld.FullName)\word"
}
}
是的,有一种方法可以做到这一点。不,我看不到你试过的代码。如果你被卡住了,请自己试一试,并征求意见。从
Get ChildItem开始