hutool.core.io.file_name¶
文件名工具模块
Module Contents¶
Classes¶
文件名工具类 |
API¶
- class hutool.core.io.file_name.FileNameUtil¶
文件名工具类
- _INVALID_CHARS = 'compile(...)'¶
- static get_name(path: str) str¶
获取文件名(含扩展名)
- 参数:
path – 文件路径
- 返回:
文件名,如 “document.txt”
- static get_prefix(path: str) str¶
获取文件名前缀(不含扩展名)
- 参数:
path – 文件路径
- 返回:
文件名前缀,如 “document”
- static get_suffix(path: str) str¶
获取扩展名(不含点)
- 参数:
path – 文件路径
- 返回:
扩展名,如 “txt”;无扩展名时返回空字符串
- static main_name(path: str) str¶
获取主文件名(等同于 get_prefix)
- 参数:
path – 文件路径
- 返回:
主文件名
- static ext_name(path: str) str¶
获取扩展名(同 get_suffix)
- 参数:
path – 文件路径
- 返回:
扩展名
- static normalize(path: str) str¶
标准化文件名路径
将路径中的反斜杠统一替换为正斜杠,并去除多余分隔符。
- 参数:
path – 文件路径
- 返回:
标准化后的路径
- static clean_invalid(name: str) str¶
清理文件名中的非法字符
移除 Windows 及通用文件系统中不允许出现的字符。
- 参数:
name – 原始文件名
- 返回:
清理后的合法文件名
- static is_type(path: str, ext: str) bool¶
检查文件扩展名是否匹配
比较时忽略大小写。
- 参数:
path – 文件路径
ext – 期望的扩展名(不含点,如 “txt”)
- 返回:
匹配返回 True,否则 False