gpt4 book ai didi

python - 检查文件系统在 Python 中是否不区分大小写

转载 作者:太空狗 更新时间:2023-10-29 17:03:03 25 4
gpt4 key购买 nike

如果文件系统不区分大小写,是否有一种简单的方法可以在 Python 中进行检查?我特别考虑像 HFS+ (OSX) 和 NTFS (Windows) 这样的文件系统,您可以在其中访问与 foo、Foo 或 FOO 相同的文件,即使保留了文件大小写。

最佳答案

import os
import tempfile

# By default mkstemp() creates a file with
# a name that begins with 'tmp' (lowercase)
tmphandle, tmppath = tempfile.mkstemp()
if os.path.exists(tmppath.upper()):
# Case insensitive.
else:
# Case sensitive.

关于python - 检查文件系统在 Python 中是否不区分大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7870041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com