6

is there any library or function that tells me the partition's type for a specific "path" in python??

or how can I accomplish that with any other approach?

thanks in advance!

juanp_1982
  • 917
  • 2
  • 16
  • 37
  • possible duplicate of [How to find the mountpoint a file resides on?](http://stackoverflow.com/questions/4453602/how-to-find-the-mountpoint-a-file-resides-on) – hek2mgl May 09 '13 at 01:23
  • 2
    It's related, but this question has an additional element (finding the partition type) that the original question did not. – Craig McQueen May 09 '13 at 01:39

2 Answers2

3

How to find the file system type in python also seems relevant.

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?).

Community
  • 1
  • 1
Andrew
  • 366
  • 2
  • 8
1

Okay, in my previous answer, I thought you need windows, however, I believe I found a way in Linux.

Try this:

By using subprocess on this command df -T /users/f/foo/file.txt , you can get the results you need.

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% /