473,769 Members | 6,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

detecting drives for windows and linux

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
Mar 25 '06 #1
7 3595
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

Mar 25 '06 #2
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
Mar 25 '06 #3
Max
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
Mar 26 '06 #4
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
Mar 26 '06 #5
al*****@yahoo.c om (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ührun g des Dreißigjährigen Krieges mit
den Mitteln einer Talkshow. [Alexander Bartolich in dcpu]
Mar 27 '06 #6
Florian Diesch <di****@spamfen ce.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
Mar 28 '06 #7
al*****@yahoo.c om (Alex Martelli) wrote:
Florian Diesch <di****@spamfen ce.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]
Mar 29 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
4366
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 anybody know how to detect the operating system under which the current Python program is running, especially whether it's Windows or Unix? I have a program that needs to search for files in "c:\test" if it's running under Windows, and...
3
465
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.. Does nmap is available on every systems? I tried on my linux fc4 machine in user previleage. it was not working. Does this just belongs to superuser...
5
3517
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 Windows, I would look up the registry, on Linux/OSX/etc. I would look in /etc/mime-types (or where the mime types are located). How would I detect the OS ? I have tried the following:
3
5710
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 file and folder manipulations. While this question is not concerning the primary purpose of the program, I think it would be a nice addition. What I'd like to be able to do is have the service be able to "detect" whenever the user attaches some...
8
6150
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 ways I have thought detecting 64bit are: 1. struct.calcsize("P") == 8 2. '64' in os.uname() I'm not convinced that either one of these is really adequate. Does
4
8714
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 form of C:\, D:\, E: \..etc
2
1573
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 course. regards Hardy
4
4561
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 GTK application that needs to adapt itself to be a Hildon application if run on devices like the N800. I have been searching around for an answer to this, and did find some messages on a lists that suggested the use of sys.platform to detect
1
3448
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 fine, not an issue. when i put my restore cd in to just install windows over the existing linux install everything goes great. accept it doesnt put a fresh windows mbr over grub. I realize if i get a restore cd i can do "fixmbr" or whatever the...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5309
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.