脚本将仅在该路径不存在时生成,根据
Test-Path
如下所示。我只能在用户删除
$dailyLocal
文件夹,当脚本的下一步尝试重建路径时,我们会看到断开的路径。
我有没有其他的参数可以用来防止这种情况发生?有人知道这个错误或者“28文件”是什么吗?
编辑:28是从日期格式,Powershell认为我正在请求生成一个扩展名为的文件。28,我已经指定了新路径应该是一个文件夹。我可以采取其他措施将其指定为文件夹吗?
#name variables
$bay = 'X1'
$hotFolder = 'C:\Hot_Folder'
$uploadArchive = 'C:\Hot_Folder\Archive'
$today = get-date -Format yyyy.MM.dd
$dailyServer = "\\server\$today $bay"
$dailyLocal = "$uploadArchive\$today $bay"
#build local archive and server archive path for date and bay (test if exists first)
if(!((Test-Path -Path $dailyServer -PathType Container) -or (Test-Path -Path $dailyLocal -PathType Container))){
New-Item -ItemType directory -Path $dailyServer, $dailyLocal
}
#copy to server archive, then move to local archive
$uploadImages = GCI $hotFolder -Filter *.jpg
foreach ($image in $uploadImages){
Write-Host "this is the new valid image" $image -ForegroundColor Green
Copy-Item $image.FullName -Destination $dailyServer -Force
Move-Item $image.FullName -Destination $dailyLocal -Force
}