简体   繁体   English

我如何知道“路径”是否位于FAT32分区中?

[英]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.

相关问题 使用python获取fat32属性 - Get fat32 attributes with python 如何在非标准路径的Python 3.3安装中正确安装pip3? - How do I correctly install pip3 in a Python 3.3 installation located at a non-standard path? 在 Python 中,如何获取位于模块内的文件目录的路径 - In Python, how do I get the path to a directory of files located within a module 给定一个hdfs路径,我怎么知道它是一个文件夹还是一个带有python的文件 - Given a hdfs path, how do I know if it is a folder or a file with python 我如何知道 linux ubuntu 上的 python 路径? - How do I know python path on linux ubuntu? 如何设置创建 gen_py 的路径 (win32com.__gen_path__) - How do I set the path where gen_py is created (win32com.__gen_path__) 我的 pip 安装在其他 PATH 中,我不想我不知道如何修改它 - My pip install in other PATH and I do not want I do not know how to modify it 这是否意味着pip安装的python路径不正确? 如果是这样,我如何知道正确的路径,然后如何更改? - Does this means the python path for pip install is incorrect? If so, how do I know the right path and then how do I change that? 如何将矩形分成4个部分? - How do I partition a rectangle into 4 parts? 我删除了anaconda,现在我的python路径搞砸了。 你知道怎么解决吗? - I removed anaconda and now my python path is messed up. Do you know how to fix it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM