文件信息服务
FileInfo 服务提供针对文件路径的各种操作,例如将绝对路径转换为相对路径,将路径拆分为组件等。
可用操作
baseName
FileInfo.baseName(filePath: string): string返回 filePath 的文件名,直到(但不包括)第一个 '.' 字符。
canonicalPath
FileInfo.canonicalPath(filePath: string): string返回规范化的 filePath,即不包含符号链接、冗余的 '.' 或 '..' 元素的绝对路径。在 Windows 上,还会解析驱动器替换。
建议仅在确实需要规范路径的情况下使用 canonicalPath。在大多数情况下,cleanPath 应该足够了。
cleanPath
FileInfo.cleanPath(filePath: string): string返回不含冗余分隔符的 filePath,以及解析了 '.' 和 '..' 组件的出现。例如,/usr/local//../bin/ 变为 /usr/bin。
completeBaseName
FileInfo.completeBaseName(filePath: string): string返回 filePath 的文件名,直到(但不包括)最后一个 '.' 字符。
completeSuffix
FileInfo.completeSuffix(filePath: string): string返回 filePath 的文件后缀,从(但不包括)最后一个 '.' 字符开始。
此函数自 1.12 版本引入。
fileName
FileInfo.fileName(filePath: string): string返回 filePath 的最后一个组件,也就是最后一个 '/' 字符之后的所有内容。
fromNativeSeparators
FileInfo.fromNativeSeparators(filePath: string): string在 Windows 主机上,此函数的行为与 fromWindowsSeparators 相同。在其他操作系统上,它返回未经修改的输入。
fromWindowsSeparators
FileInfo.fromWindowsSeparators(filePath: string): string返回所有 '\ ' 字符被 '/' 替换的 filePath。
isAbsolutePath
FileInfo.isAbsolutePath(filePath: string, hostOS?: string[]): boolean
如果 filePath 是绝对路径,则返回 true;如果是相对路径,则返回 false。如果指定了 hostOS,则将 filePath 视为在该平台上找到的文件路径。此参数默认为主机 OS,应通常省略。
joinPaths
FileInfo.joinPaths(...paths: string[]): string
使用 '/' 字符连接给定的路径。
path
FileInfo.path(filePath: string, hostOS?: string[]): string
返回filePath中不是文件名的部分,即包括最后一个'/'字符(但不包括)的所有内容。如果filePath仅是一个文件名,则返回'.'。如果filePath以'/'字符结尾,则根据上述定义,假设文件名为空。如果指定了hostOS,则将filePath视为在该平台找到的类型文件路径。此参数默认为主机操作系统上运行的Qbs主机,通常可以省略。
relativePath
FileInfo.relativePath(dirPath: string, filePath: string): string
返回一个相对路径,将dirPath和返回的路径连接起来将得到filePath。如果有必要,将插入'..'组件。该函数假定dirPath和filePath为绝对路径,并且dirPath为一个目录。
suffix
FileInfo.suffix(filePath: string): string从第一个'.'字符(但不包括)返回filePath的文件后缀。
此函数自 1.12 版本引入。
toNativeSeparators
FileInfo.toNativeSeparators(filePath: string): string在Windows主机上,此函数的行为与toWindowsSeparators相同。在其他操作系统上,它返回未修改的输入。
toWindowsSeparators
FileInfo.toWindowsSeparators(filePath: string): string将所有'/'字符替换为'\', 返回filePath
pathListSeparator
FileInfo.pathListSeparator(): string返回路径列表的主机操作系统分隔符,用于环境变量或其他上下文。
此功能从版本1.22开始引入。
pathSeparator
FileInfo.pathSeparator(): string返回主机操作系统的路径分隔符。
此功能从版本1.22开始引入。
executableSuffix
FileInfo.executableSuffix(): string返回主机操作系统的可执行文件后缀。
此功能从版本1.23开始引入。
©2023 The Qt Company Ltd. 本文档的贡献包括各个所有者的版权。本提供的文档是根据自由软件基金会发布的GNU自由文档许可证版本1.3的条款许可的。Qt和相应的标志是The Qt Company Ltd在芬兰和/或其他国家的商标。所有其他商标均为各自所有者的财产。