ฉันมีสคริปต์ที่ฉันใช้ในการสำรองไฟล์ ด้วยเหตุผลบางอย่างมันเป็นเพียงการคัดลอกไฟล์และ dir ของโฟลเดอร์ย่อยเมื่อสคริปต์ทำงาน ข้อความแสดงข้อผิดพลาดคือ
"ไม่สามารถคัดลอกคอนเทนเนอร์ไปยังรายการใบไม้ที่มีอยู่"
ฉันค้นหาข้อผิดพลาดนี้และพวกเขาบอกว่าฉันกำลังคัดลอกไฟล์ไปยังชื่อไฟล์เดียวกัน แต่นี่เป็นส่วนย่อยที่ไม่ได้ถูกสร้างขึ้นในครั้งแรกที่สคริปต์ทำงาน โฟลเดอร์ปลายทางว่างเปล่าในครั้งแรกที่ฉันเรียกใช้ ความคิดใด ๆ
แหล่งที่มามีลักษณะเช่นนี้:
\\DRIVE01\Svcs
\Credential
\Forms
file and dir list #this dir level doesn't get copied the first time, but the files do
นี่คือสิ่งที่ toLoc ดูเหมือนหลังจากการดำเนินการครั้งแรก:
me\Documents\2018\powershellFiles\toLoc
\Credential
\Forms
file list #the first time the files get copied without the dirs at this level
นี่คือสคริปต์ของฉัน:
function CopyFileToFolderUNC($SourcePath, $DestinationPath){
Copy-Item -Path $SourcePath/* -Destination $DestinationPath #Copy-Item -Path source -Destination target -Recurse -Force
}
#################start here##################################
$tempSource = @("\\DRIVE01\Svcs\Credentialing\FORMS") #eventually will have list of more than one here
$ToLocation = "C:\Users\me\Documents\2018 \powershellFiles\toLoc\Credentialing\FORMS\" #this will eventually be array with multiple in it
for($i=0; $i -lt ($tempSource.Length); $i++) {
CopyFileToFolderUNC $tempSource[$i] $ToLocation
}
ก่อนที่ฉันจะเปลี่ยนเป็น for for loop จาก foreach ฉันคิดว่ามันทำงานให้กับ subdir ใน toLoc ฉันต้องการสำหรับลูปเพราะมันจะง่ายต่อการจัดการกับอาร์เรย์สำหรับสตริงต้นทางและปลายทาง dir ซึ่งจะเป็นต่อไป