在PowerShell中,你可以投URL字符串System.Uri
類提供有關URL及其結構的大量信息。您可能需要Uri.Segments財產的工作情況如下:
PS C:\> # get System.Uri object:
PS C:\> $uri = [uri]"http://Repository.com/Stuff/Things/Repo/file1.csv"
PS C:\> $uri
AbsolutePath : /Stuff/Things/Repo/file1.csv
AbsoluteUri : http://repository.com/Stuff/Things/Repo/file1.csv
LocalPath : /Stuff/Things/Repo/file1.csv
Authority : repository.com
HostNameType : Dns
IsDefaultPort : True
IsFile : False
IsLoopback : False
PathAndQuery : /Stuff/Things/Repo/file1.csv
Segments : {/, Stuff/, Things/, Repo/...}
IsUnc : False
Host : repository.com
Port : 80
Query :
Fragment :
Scheme : http
OriginalString : http://Repository.com/Stuff/Things/Repo/file1.csv
DnsSafeHost : repository.com
IsAbsoluteUri : True
UserEscaped : False
UserInfo :
PS C:\> # get base URL without page name and query parameters:
PS C:\> $uri.Scheme + ":/" + $uri.Authority + (-join $uri.Segments[0..($uri.Segments.Length - 2)])
http:/repository.com/Stuff/Things/Repo/
PS C:\> # get page/file name:
PS C:\> $uri.Segments[-1]
file1.csv
這一個沒有做出多語言的陳述就是我今天想要的。謝謝。 –
我認爲做echo「'%%〜DPa」可以做到這一點。 – Paul
@保羅:不,它不起作用。看到阿卜杜拉的回答如下... – Aacini