我想檢查 file.txt 是否存在。如果存在,請洗掉并重新安裝。如果它不存在,請下載它。
Test-Path -Path file.txt -PathType Leaf
Remove-Item 'file.txt'
Invoke-WebRequest -Uri http://example.com/file.txt -OutFile file.txt
我似乎無法弄清楚如何將其放入 if 陳述句中(我是 Powershell 的新手)。
uj5u.com熱心網友回復:
if (Test-Path -Path file.txt -PathType Leaf){
Remove-Item file.txt
Invoke-WebRequest -Uri http://example.com/file.txt -OutFile file.txt
}
else{
Invoke-WebRequest -Uri http://example.com/file.txt -OutFile file.txt
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/432506.html
上一篇:迭代兩個資料框以在R中創建標準列
