Hi, I'm writing a file browser, but I'm not sure how I could go about
detecting the drives available on windows and linux systems (preferably
using the standard modules if possible). I guess I could just try to
list root on each letter of the alphabet for windows and see if it
works, but that seems crude; besides, I want to know what kind of drive
each drive/partition is (i.e. is it local and is it a harddrive or
optical drive).
Thanks,
Brian 7 3569
BWill wrote: Hi, I'm writing a file browser, but I'm not sure how I could go about detecting the drives available on windows and linux systems (preferably using the standard modules if possible). I guess I could just try to list root on each letter of the alphabet for windows and see if it works, but that seems crude; besides, I want to know what kind of drive each drive/partition is (i.e. is it local and is it a harddrive or optical drive).
I'm not aware of any cross-platform way of doing this.
On Windows you have a few options, but I'd go down
the WMI route; it just makes life easier for doing this
kind of thing. You might want to start by adapting this
example: http://tgolden.sc.sabren.com/python/...ercentage_free
by removing the restriction to fixed disk (DriveType=3)
TJG
Tim Golden wrote: BWill wrote: Hi, I'm writing a file browser, but I'm not sure how I could go about detecting the drives available on windows and linux systems (preferably using the standard modules if possible). I guess I could just try to list root on each letter of the alphabet for windows and see if it works, but that seems crude; besides, I want to know what kind of drive each drive/partition is (i.e. is it local and is it a harddrive or optical drive).
I'm not aware of any cross-platform way of doing this. On Windows you have a few options, but I'd go down the WMI route; it just makes life easier for doing this kind of thing. You might want to start by adapting this example:
http://tgolden.sc.sabren.com/python/...ercentage_free
by removing the restriction to fixed disk (DriveType=3)
TJG
oh, I wasn't expecting a single solution for both platforms, just some
good solutions
thanks
BWill wrote: oh, I wasn't expecting a single solution for both platforms, just some good solutions
thanks
Are you aware that this idea is somewhat foreign to Linux? (Maybe you
are and want to do it anyway?) Linux puts the whole file system
(including mounted iPods, ISOs and NTFS drives) in one hierarchy.
--Max
Max <rabkin@mweb[DOT]co[DOT]za> wrote: BWill wrote:
oh, I wasn't expecting a single solution for both platforms, just some good solutions
thanks
Are you aware that this idea is somewhat foreign to Linux? (Maybe you are and want to do it anyway?) Linux puts the whole file system (including mounted iPods, ISOs and NTFS drives) in one hierarchy.
Yes, but you may still want to distinguish (because, for example, hard
linking doesn't work across filesystems, and mv is not atomic then).
Running a df command is a good simple way to find out what drives are
mounted to what mountpoints -- the mount command is an alternative, but
its output may be slightly harder to parse than df's.
Alex al*****@yahoo.com (Alex Martelli) wrote: Max <rabkin@mweb[DOT]co[DOT]za> wrote:
BWill wrote:
> oh, I wasn't expecting a single solution for both platforms, just some > good solutions > > thanks Are you aware that this idea is somewhat foreign to Linux? (Maybe you are and want to do it anyway?) Linux puts the whole file system (including mounted iPods, ISOs and NTFS drives) in one hierarchy.
Yes, but you may still want to distinguish (because, for example, hard linking doesn't work across filesystems, and mv is not atomic then).
Why not use os.stat?
Running a df command is a good simple way to find out what drives are mounted to what mountpoints -- the mount command is an alternative, but its output may be slightly harder to parse than df's.
Executing df may be expensive if it needs to read some slow file systems.
Reading /etc/mtab is not difficult and much faster.
Florian
--
Das toitsche Usenet ist die Wiederaufführung des Dreißigjährigen Krieges mit
den Mitteln einer Talkshow. [Alexander Bartolich in dcpu]
Florian Diesch <di****@spamfence.net> wrote:
... are and want to do it anyway?) Linux puts the whole file system (including mounted iPods, ISOs and NTFS drives) in one hierarchy. Yes, but you may still want to distinguish (because, for example, hard linking doesn't work across filesystems, and mv is not atomic then).
Why not use os.stat?
Each os.stat call gives you information about one file (or directory);
it may be simpler and faster to get the information "in bulk" once and
for all. Running a df command is a good simple way to find out what drives are mounted to what mountpoints -- the mount command is an alternative, but its output may be slightly harder to parse than df's.
Executing df may be expensive if it needs to read some slow file systems.
That's what the -n flag is for, if you're worried about that (although I
believe it may not be available on all systems) -- executing mount is
the alternative (just putting up with some parsing difficulties
depending, e.g., on what automounters may be doing).
Reading /etc/mtab is not difficult and much faster
$ cat /etc/mtab
cat: /etc/mtab: No such file or directory
Oops! BSD systems don't have /etc/mtab... so, if you choose to get your
info by reading it, you've just needlessly destroyed your program's
compatibility with a large portion of the Unix-y universe. popen a
mount or df, and information will be easier to extract portably.
Alex al*****@yahoo.com (Alex Martelli) wrote: Florian Diesch <di****@spamfence.net> wrote: ... >> are and want to do it anyway?) Linux puts the whole file system >> (including mounted iPods, ISOs and NTFS drives) in one hierarchy. > > Yes, but you may still want to distinguish (because, for example, hard > linking doesn't work across filesystems, and mv is not atomic then). Why not use os.stat?
Each os.stat call gives you information about one file (or directory); it may be simpler and faster to get the information "in bulk" once and for all.
Depends on what you want to do. Offen you need informations like file size,
permissions or owner in any case.
For things like creating hardlinks it may be the best to just try it and
catch the exception. > Running a df command is a good simple way to find out what drives are > mounted to what mountpoints -- the mount command is an alternative, but > its output may be slightly harder to parse than df's.
Executing df may be expensive if it needs to read some slow file systems.
That's what the -n flag is for, if you're worried about that (although I believe it may not be available on all systems) --
GNU df doesn't have it.
Some of the various version of df at Solaris don't have it too. And they
have at least two different output formats.
executing mount is the alternative (just putting up with some parsing difficulties depending, e.g., on what automounters may be doing).
I would prefer mount as ir is cheaper than df Reading /etc/mtab is not difficult and much faster
$ cat /etc/mtab cat: /etc/mtab: No such file or directory
Ok, wasn't that clever. On Solaris it's /etc/mntab, I don't have any BSD around
Oops! BSD systems don't have /etc/mtab... so, if you choose to get your info by reading it, you've just needlessly destroyed your program's compatibility with a large portion of the Unix-y universe. popen a mount or df, and information will be easier to extract portably.
On the other hand I know of at least two boxes (no, not mine) where
ordinary users don't have permission to exec mount.
Florian
--
Emacs doesn't crash! It contains very little C, so there's very
little reason to have it crash. [Pascal Bourguignon in gnu.emacs.help] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Woojay Jeon |
last post by:
OK, I tried a Google search on this Usenet group but couldn't find a
solution, so I'm posting my question here (if there's a better archive than
the one in Google, please let me know).
Does...
|
by: Sandeep Arya |
last post by:
Thanks linuxfreak and sybren for positive comments
My application will be running on Linux.
How to send ICMP ECHO as broadcast packets. I do not know this. Please tell
me how to?
Sybren.....
|
by: Christoffer Soerensen |
last post by:
Hi,
I am currently building an application in C# using mono and .NET. I
want to get a MIME type for a specific file, which is why I want to
detect the OS on which the application is running. On...
|
by: Max |
last post by:
Not sure exactly how to describe this or if it's even possible, so I'll
do my best and would appreciate some suggestions.
I'm currently working on a service that will allow me to automate some...
|
by: dwelch91 |
last post by:
I need to detect whether the operating system I am running on (not the
Python version) is 64bit or 32bit. One requirement is that I need to
include support for non-Intel/AMD architectures.
The 2...
|
by: yellowblueyellow |
last post by:
Hey All,
I am using the following line of code to pick all logical drives on
the local machine:
string drives = Directory.GetLogicalDrives();
using the above code I can get output in the...
|
by: HardySpicer |
last post by:
Some pcs have only the c drive whilst others like mine have c,d,e,f
and z! How do I detect this automatically if I want to search all
drives in a pc? I also want to ignore the DVD and floppy of...
|
by: Devraj |
last post by:
Hi everyone,
My Python program needs reliably detect which Operating System its
being run on, infact it even needs to know which distribution of say
Linux its running on. The reason being its a...
|
by: scotter86 |
last post by:
Hey everyone, for the love of god i cannot get this straight. I have 2 hard drives, each runing windows xp home. I installed linux on my second hard drive and it over wrote the windows mbr. thats...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |