parse_path()parse_path()

分析文件路径 string,并返回包含该路径的以下部分的 dynamic 对象:Parses a file path string and returns a dynamic object that contains the following parts of the path:

  • SchemeScheme
  • RootPathRootPath
  • DirectoryPathDirectoryPath
  • DirectoryNameDirectoryName
  • FileNameFileName
  • 分机Extension
  • AlternateDataStreamNameAlternateDataStreamName

除了具有两种斜杠类型的简单路径外,此函数还支持包含以下内容的路径:In addition to the simple paths with both types of slashes, the function supports paths with:

  • 架构。Schemas. 例如,“file://...”For example, "file://..."
  • 共享路径。Shared paths. 例如,“\shareddrive\users...”For example, "\shareddrive\users..."
  • 长路径。Long paths. 例如,“\?\C:...”For example, "\?\C:...""
  • 备用数据流。Alternate data streams. 例如,“file1.exe:file2.exe”For example, "file1.exe:file2.exe"

语法Syntax

parse_path(path)parse_path(path)

参数Arguments

  • path:一个表示文件路径的字符串。path: A string that represents a file path.

返回Returns

包含上面列出的路径组件的 dynamic 类型的对象。An object of type dynamic that included the path components as listed above.

示例Example

datatable(p:string) 
[
    @"C:\temp\file.txt",
    @"temp\file.txt",
    "file://C:/temp/file.txt:some.exe",
    @"\\shared\users\temp\file.txt.gz",
    "/usr/lib/temp/file.txt"
]
| extend path_parts = parse_path(p)

pp path_partspath_parts
C:\temp\file.txtC:\temp\file.txt {"Scheme":"","RootPath":"C:","DirectoryPath":"C:\temp","DirectoryName":"temp","Filename":"file.txt","Extension":"txt","AlternateDataStreamName":""}{"Scheme":"","RootPath":"C:","DirectoryPath":"C:\temp","DirectoryName":"temp","Filename":"file.txt","Extension":"txt","AlternateDataStreamName":""}
temp\file.txttemp\file.txt {"Scheme":"","RootPath":"","DirectoryPath":"temp","DirectoryName":"temp","Filename":"file.txt","Extension":"txt","AlternateDataStreamName":""}{"Scheme":"","RootPath":"","DirectoryPath":"temp","DirectoryName":"temp","Filename":"file.txt","Extension":"txt","AlternateDataStreamName":""}
file://C:/temp/file.txt:some.exefile://C:/temp/file.txt:some.exe {"Scheme":"file","RootPath":"C:","DirectoryPath":"C:/temp","DirectoryName":"temp","Filename":"file.txt","Extension":"txt","AlternateDataStreamName":"some.exe"}{"Scheme":"file","RootPath":"C:","DirectoryPath":"C:/temp","DirectoryName":"temp","Filename":"file.txt","Extension":"txt","AlternateDataStreamName":"some.exe"}
\shared\users\temp\file.txt.gz\shared\users\temp\file.txt.gz {"Scheme":"","RootPath":"","DirectoryPath":"\\shared\users\temp","DirectoryName":"temp","Filename":"file.txt.gz","Extension":"gz","AlternateDataStreamName":""}{"Scheme":"","RootPath":"","DirectoryPath":"\\shared\users\temp","DirectoryName":"temp","Filename":"file.txt.gz","Extension":"gz","AlternateDataStreamName":""}
/usr/lib/temp/file.txt/usr/lib/temp/file.txt {"Scheme":"","RootPath":"","DirectoryPath":"/usr/lib/temp","DirectoryName":"temp","Filename":"file.txt","Extension":"txt","AlternateDataStreamName":""}{"Scheme":"","RootPath":"","DirectoryPath":"/usr/lib/temp","DirectoryName":"temp","Filename":"file.txt","Extension":"txt","AlternateDataStreamName":""}