gpt4 book ai didi

powershell - 移动项目 “the path is not supported.”

转载 作者:行者123 更新时间:2023-12-03 01:11:31 25 4
gpt4 key购买 nike

我们有一个脚本可以成功将文件夹压缩到7z,然后在压缩后删除该文件夹。
我们要做的是将压缩的7z文件移动到另一个位置,该位置位于较便宜的存储位置,也用于备份/异地归档。

我尝试了以下操作,但出现错误“不支持该路径”。

有人可以协助吗?

Get-ChildItem 'E:\AbleyTest\TestFolder\_Archived\*' | Where-Object {
$_.PSIsContainer
} | Select-Object -Expand FullName | ForEach-Object {
& 7z.exe a -mx=9 -t7z "$_.7z" "$_"
if ($LastExitCode -eq 0) {
$folder = (Get-Item $_).Parent.Parent.Name
if (Test-Path "e:\archived\$folder") {
Move-Item -Path "$_.7z" -Destination "e:\archived\$folder\$_.7z"
} else {
New-Item "e:\archived\$folder" -Type directory
Move-Item -Path "$_.7z" -Destination "e:\archived\$folder\$_.7z"
}
Remove-Item -Path $_ -Force -Recurse
} else {
Add-Content "e:\scripts\archivelog $(get-date -f dd-MM-yyyy).txt" "$_ ran into error $LastExitCode while archiving"
}
}

最佳答案

您的目标路径无效。考虑到$_是某个文件夹的完整路径(例如E:\AbleyTest\TestFolder\_Archived\SomeFolder,您的目标路径是:

"e:\archived\$folder\$_.7z"

突然变成:
e:\archived\TestFolder\E:\AbleyTest\TestFolder\_Archived\SomeFolder.7z

编辑:我刚刚意识到我已经告诉过您问题了,但并没有真正帮助您解决问题。目标路径不需要文件名(它保留要在目标位置使用的文件名),因此只需在 $folder之后停止,就可以了:
Move-Item -Path "$_.7z" -Destination "e:\archived\$folder"

关于powershell - 移动项目 “the path is not supported.”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38906871/

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