Powershell 在使用 rightclick->open with 时在“copy-item”期间死机,但在 powershell 中打开路径手册时没问题

Powershell dies during "copy-item" when using rightclick->open with but is fine when opening the path manual in powershell

提问人:Steini 提问时间:11/14/2023 最后编辑:Steini 更新时间:11/15/2023 访问量:27

问:

我有一个powershell脚本,它从带有一些过滤器的路径中复制了很多文件。

非常奇怪的行为: 当我使用以下命令打开 powershell 脚本时: 右键单击>使用 powershell(或双击)run

脚本在复制命令时死亡。

当我打开一个空白的 powershell 时, 使用“cd”转到脚本所在的路径 然后使用 \run.ps1 运行 Shellscript

然后它工作正常。

在这两种情况下,回声“$($pwd)”的回声是相同的。

是否有已知的错误,或者我可以做任何事情来使用右键单击方法使其工作?

我的脚本的相关行。当我注释掉“Copy-Item”路径时,脚本正常工作。

if($null -eq $env:DEVROOT) {
    echo "Error: Please configure Windows environment-variable DEVROOT 
to the root-folder of your projects."
    pause
    return
}

$devRootPath = "$env:DEVROOT"

$copyExcludes = ".git",".svn",".idea",".vscode"
$destinationPath = "code-temp-store\"
Get-ChildItem "$($devRootPath)\lma\" | Where-Object{$_.Name -notin $copyExcludes} | 
Copy-Item -Destination $destinationPath -Recurse -Force
PowerShell 文件 复制

评论

0赞 Theo 11/15/2023
1)你没有使用,而是写了空格2)您的excludes数组仅包含扩展名,因此不起作用,并且会传递任何文件。3)我在您的代码中没有看到定义。4)目前尚不清楚是否也要复制文件或目录。Copy-ItemCopy-Item$_.Name -notin $copyExcludes$devRootPath
0赞 Steini 11/15/2023
@up 1) 复制 - 空白在将我的代码从编辑器复制到 Stackoverflow 时意外发生。换行符看起来很奇怪,想把它“放到位”,却不小心犯了一个错误。但是,我现在修复了帖子及其与我的代码相同的内容。2) 不包括 WORK,否则我会在我的 copy-temp-store 中有我没有的 .git 文件夹等。3) $devRootPath 是一个环境变量。我忘了粘贴我更新了帖子。 4)我想“按原样”复制文件和目录。整个结构。

答: 暂无答案