[英]how do I know if a “path” is located in a FAT32 partition?
is there any library or function that tells me the partition's type for a specific "path" in python?? 是否有任何库或函数告诉我python中特定“路径”的分区类型?
or how can I accomplish that with any other approach? 或者我怎样才能通过其他方法实现这一目标?
thanks in advance! 提前致谢!
How to find the file system type in python also seems relevant. 如何在python中找到文件系统类型似乎也很相关。
Here's what I came up with: 这是我想出的:
import subprocess
import os
def is_filesys_fat32(path):
try:
subprocess.check_call(['df', '--type=fat32', path], stdout=os.devnull)
except:
return False
return True
Assuming you're running linux (as the tag mentions), and that you're only searching for existence of the type, not getting the type (use a regex on subprocess.check_output()
using the same command?). 假设您正在运行linux(作为标记提及),并且您只搜索类型的存在,而不是获取类型(使用相同的命令在subprocess.check_output()
使用正则表达式?)。
Okay, in my previous answer, I thought you need windows, however, I believe I found a way in Linux. 好的,在我之前的回答中,我认为你需要Windows,但是,我相信我在Linux中找到了一种方法。
Try this: 试试这个:
By using subprocess on this command df -T /users/f/foo/file.txt
, you can get the results you need. 通过在此命令df -T /users/f/foo/file.txt
上使用子df -T /users/f/foo/file.txt
,您可以获得所需的结果。
import subprocess
p = subprocess.Popen(["df -T %s"] % path, stdout=subprocess.PIPE)
out, err = p.communicate()
Sample output: 样本输出:
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda5 ext4 472439072 146088944 302351616 33% /
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.