我的目标是等待文件下载;用户将因此更改%userprofile%
我似乎无法破解,一旦文件被下载,id就像移动到C的根目录。
while (!(Test-Path "%userprofile%downloadsname.exe")) { start-sleep 10 }
$File = "%userprofile%downloadsname.exe"
if (Test-Path $File) {
Move-Item $File c: -Force
}
在我使用PowerShell的短暂时间中,我一直在为目录而苦苦挣扎
使用 $env:USERPROFILE
变量确定用户配置文件,并使用 Join-Path
cmdlet 组合路径:
$filePath = Join-Path $env:USERPROFILE 'downloadsname.exe'
while (-not (Test-Path $filePath))
{
start-sleep 10
}
if (Test-Path $filePath)
{
Move-Item -Path $filePath -Destination 'c:' -Force
}