PowerShell工作目錄路徑含中括號字元問題 - Windows

By Adele
at 2020-10-22T18:28
at 2020-10-22T18:28
Table of Contents
作業系統:Windows 10
Service Pack:20H2
發生問題頻率:100%
是否有做Windows Update:有
問題內容:PowerShell工作目錄路徑中帶有中括號導致結果不如預期
PS D:\> Test-Path -LiteralPath "D:\[test] videos\test video 1.mp4"
True
PS D:\> Test-Path -LiteralPath "D:\test videos\test video 1.mp4"
True
PS D:\> Set-Location -LiteralPath "D:\test videos"
PS D:\test videos> Test-Path -LiteralPath "test video 1.mp4"
True
PS D:\test videos> Set-Location -LiteralPath "D:\[test] videos"
PS D:\[test] videos> Test-Path -LiteralPath "test video 1.mp4"
False
PS D:\[test] videos> $env:Path = "C:\ffmpeg\bin;" + $env:Path
PS D:\[test] videos> Start-Process -FilePath "ffmpeg" -ArgumentList '-i "test
video 1.mp4" -c copy output.mkv' -NoNewWindow -PassThru -Wait
Start-Process : 無法執行作業,因為萬用字元路徑 D:\[test] videos 無法解析成檔案
。
位於 線路:1 字元:1
+ Start-Process -FilePath "ffmpeg" -ArgumentList '-i "test video 1.mp4" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (D:\[test] videos:String) [Start-
Process], FileNotFoundException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.
StartProcessCommand
如上所示若工作目錄中帶有中括號時用Test-Path判斷相對路徑皆回傳False
Start-Process命令也會發生發生錯誤...
我想請問,除了使用絕對路徑以外有什麼解決方法?
--
Service Pack:20H2
發生問題頻率:100%
是否有做Windows Update:有
問題內容:PowerShell工作目錄路徑中帶有中括號導致結果不如預期
PS D:\> Test-Path -LiteralPath "D:\[test] videos\test video 1.mp4"
True
PS D:\> Test-Path -LiteralPath "D:\test videos\test video 1.mp4"
True
PS D:\> Set-Location -LiteralPath "D:\test videos"
PS D:\test videos> Test-Path -LiteralPath "test video 1.mp4"
True
PS D:\test videos> Set-Location -LiteralPath "D:\[test] videos"
PS D:\[test] videos> Test-Path -LiteralPath "test video 1.mp4"
False
PS D:\[test] videos> $env:Path = "C:\ffmpeg\bin;" + $env:Path
PS D:\[test] videos> Start-Process -FilePath "ffmpeg" -ArgumentList '-i "test
video 1.mp4" -c copy output.mkv' -NoNewWindow -PassThru -Wait
Start-Process : 無法執行作業,因為萬用字元路徑 D:\[test] videos 無法解析成檔案
。
位於 線路:1 字元:1
+ Start-Process -FilePath "ffmpeg" -ArgumentList '-i "test video 1.mp4" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (D:\[test] videos:String) [Start-
Process], FileNotFoundException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.
StartProcessCommand
如上所示若工作目錄中帶有中括號時用Test-Path判斷相對路徑皆回傳False
Start-Process命令也會發生發生錯誤...
我想請問,除了使用絕對路徑以外有什麼解決方法?
--
Tags:
Windows
All Comments

By Hazel
at 2020-10-24T12:01
at 2020-10-24T12:01

By Lauren
at 2020-10-25T13:28
at 2020-10-25T13:28

By Lauren
at 2020-10-27T23:56
at 2020-10-27T23:56

By Kristin
at 2020-10-29T17:01
at 2020-10-29T17:01

By Gilbert
at 2020-11-01T10:45
at 2020-11-01T10:45

By Brianna
at 2020-11-05T11:23
at 2020-11-05T11:23

By Mia
at 2020-11-06T17:26
at 2020-11-06T17:26

By Joseph
at 2020-11-11T01:57
at 2020-11-11T01:57

By Victoria
at 2020-11-12T15:13
at 2020-11-12T15:13

By Jacky
at 2020-11-16T19:56
at 2020-11-16T19:56

By Andrew
at 2020-11-20T19:11
at 2020-11-20T19:11

By Oliver
at 2020-11-25T19:04
at 2020-11-25T19:04

By Madame
at 2020-11-27T02:41
at 2020-11-27T02:41

By Hamiltion
at 2020-11-28T18:12
at 2020-11-28T18:12
Related Posts
SL Go 22888元起

By Doris
at 2020-10-22T10:41
at 2020-10-22T10:41
買surface go 2頂規?

By Delia
at 2020-10-21T22:55
at 2020-10-21T22:55
WIN10 沒聲音

By Necoo
at 2020-10-21T09:40
at 2020-10-21T09:40
現在2004版是否還是一堆問題?(U・ω・U)

By Caroline
at 2020-10-21T01:09
at 2020-10-21T01:09
微軟放棄手機系統的後遺症?

By Odelette
at 2020-10-20T18:16
at 2020-10-20T18:16