473,608 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

analyzing removable media

Hi
can anyone tell me how given a directory or file path, I can
pythonically tell if that item is on 'removable media', or sometype of
vfs, the label of the media (or volume) and perhaps any other details
about the media itself?
thanks
Glenn

Sep 29 '06 #1
7 2279
Jay
Well, in linux you can get a lot of info about where a file is based
upon where it lies in the file system. For example, if the folder the
file is located in resides in the /media or /mnt directories, then the
file is, barring a few rare circumstances, located upon a removable
medium of some sort. Once you get the name of that directory that is
right below /media or /mnt, then you can cross check the name in
/etc/fstab file.

However, the contents of your post lead me to believe that you're
working in a win32 environment. That's a bit trickier. Things aren't
so simple. You could probably grab similar information from the full
path itself. For example, just getting the drive letter that the file
resides on could tell you a lot. Now, where you'd cross check that is
more of a mystery to me. I'd guess the registry? For an easier way of
accessing the registry, I believe that the wrapper pywin32 may be of
interest to you. It shouldn't be that hard considering that you'd only
be getting some information, not setting anything.

If by chance we're talking about MacOS, I'm of almost no help. In the
case of MacOS X, it has a unix core, so I'd imagine that the method I
described for linux could probably be adapted.

Jay

glenn wrote:
Hi
can anyone tell me how given a directory or file path, I can
pythonically tell if that item is on 'removable media', or sometype of
vfs, the label of the media (or volume) and perhaps any other details
about the media itself?
thanks
Glenn
Sep 29 '06 #2
Hi Jay
pls excuse top post - Im actually doing this project in linux, but am
wanting it to be cross platform. I definitley have to cater for win32
also. I was hoping that burried in sys or os or that there'd be some x
platform module that did all that stuff for me

thnks for reply though
glenn
Jay wrote:
Well, in linux you can get a lot of info about where a file is based
upon where it lies in the file system. For example, if the folder the
file is located in resides in the /media or /mnt directories, then the
file is, barring a few rare circumstances, located upon a removable
medium of some sort. Once you get the name of that directory that is
right below /media or /mnt, then you can cross check the name in
/etc/fstab file.

However, the contents of your post lead me to believe that you're
working in a win32 environment. That's a bit trickier. Things aren't
so simple. You could probably grab similar information from the full
path itself. For example, just getting the drive letter that the file
resides on could tell you a lot. Now, where you'd cross check that is
more of a mystery to me. I'd guess the registry? For an easier way of
accessing the registry, I believe that the wrapper pywin32 may be of
interest to you. It shouldn't be that hard considering that you'd only
be getting some information, not setting anything.

If by chance we're talking about MacOS, I'm of almost no help. In the
case of MacOS X, it has a unix core, so I'd imagine that the method I
described for linux could probably be adapted.

Jay

glenn wrote:
Hi
can anyone tell me how given a directory or file path, I can
pythonically tell if that item is on 'removable media', or sometype of
vfs, the label of the media (or volume) and perhaps any other details
about the media itself?
thanks
Glenn
Sep 29 '06 #3

glenn wrote:
Hi Jay
pls excuse top post - Im actually doing this project in linux, but am
wanting it to be cross platform. I definitley have to cater for win32
also. I was hoping that burried in sys or os or that there'd be some x
platform module that did all that stuff for me
Things don't get buried. If it's not in the documentation, it's not
there.

Sep 29 '06 #4
glenn wrote:
Hi
can anyone tell me how given a directory or file path, I can
pythonically tell if that item is on 'removable media', or sometype of
vfs, the label of the media (or volume) and perhaps any other details
about the media itself?
thanks
Glenn
It won't be trivial because one of the goals of the operating systems
is to hide the differences between various types of storage devices and
make them all look the same (i.e. a jump drive, a CD-ROM, a network
volume are presented uniformly to the user as just another path in the
file system).

But you can probably use guesswork on unix OS's, as somebody above
suggested, and examine the path. If the path contains common media
mount points then that should give you a clue. On Windows you cannot
easily know. For example if your file is on D:\file.txt, it is not
immediatly obvious if D is a jumpdrive, a networked drive, a hard
drive, or a CD-ROM.

The only thing I can think of is to try to examine the Windows registry
with the _winreg module. Here are the docs:
http://docs.python.org/lib/module--winreg.html There might be a key
burried in there some place that will tell you which drives are what
type.

Sep 29 '06 #5
Jay
Dennis is absolutely right. The reason you won't find a method in the
standard libraries for doing this task specifically is because python
aims to by cross-platform. If it were to support a method that worked
in the way you describe specifically for Windows, that would
essentially break python's cross-platform compatibility. It would
create a method that simply wouldn't work on two of the three major
operating systems. Sorry.

You could write a method or series of methods that does the task you're
describing and have the first method in the chain detect what operating
system it is running on (which I believe is possible through the
standard library) and route the request to the appropriate OS-specific
method.

Just a thought.

Jay
Dennis Lee Bieber wrote:
On 28 Sep 2006 23:23:23 -0700, "glenn" <gl***@tangelos oftware.net>
declaimed the following in comp.lang.pytho n:
Hi Jay
pls excuse top post - Im actually doing this project in linux, but am
wanting it to be cross platform. I definitley have to cater for win32
also. I was hoping that burried in sys or os or that there'd be some x
platform module that did all that stuff for me

As soon as you ask for "cross platform" and something that is
device/OS specific... you have conflict.

From the win32 extensions:

win32file.GetDr iveType
int = GetDriveType()

Determines whether a disk drive is a removable, fixed, CD-ROM, RAM disk,
or network drive.

Return Value
The result is one of the DRIVE_* constants.

I suspect Linux would require checking parameters in the fstab file.
--
Wulfraed Dennis Lee Bieber KD6MOG
wl*****@ix.netc om.com wu******@bestia ria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@bestia ria.com)
HTTP://www.bestiaria.com/
Sep 29 '06 #6
>
As soon as you ask for "cross platform" and something that is
device/OS specific... you have conflict.

From the win32 extensions:

win32file.GetDr iveType
int = GetDriveType()

Determines whether a disk drive is a removable, fixed, CD-ROM, RAM disk,
or network drive.

Return Value
The result is one of the DRIVE_* constants.

I suspect Linux would require checking parameters in the fstab file.
Thanks for the tip Dennis

Sep 30 '06 #7

Nick Vatamaniuc wrote:
glenn wrote:
Hi
can anyone tell me how given a directory or file path, I can
pythonically tell if that item is on 'removable media', or sometype of
vfs, the label of the media (or volume) and perhaps any other details
about the media itself?
thanks
Glenn

It won't be trivial because one of the goals of the operating systems
is to hide the differences between various types of storage devices and
make them all look the same (i.e. a jump drive, a CD-ROM, a network
volume are presented uniformly to the user as just another path in the
file system).

But you can probably use guesswork on unix OS's, as somebody above
suggested, and examine the path. If the path contains common media
mount points then that should give you a clue. On Windows you cannot
easily know. For example if your file is on D:\file.txt, it is not
immediatly obvious if D is a jumpdrive, a networked drive, a hard
drive, or a CD-ROM.

The only thing I can think of is to try to examine the Windows registry
with the _winreg module. Here are the docs:
http://docs.python.org/lib/module--winreg.html There might be a key
burried in there some place that will tell you which drives are what
type.
ok - thanks - will look at that - Any one know what a Mac approach
might be? can I expect that playing anything I write with fstab or
`mount` will work on OSX?, or anyother BSD for that matter?

Sep 30 '06 #8

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

Similar topics

0
2591
by: Garet Cammer | last post by:
Hi Everyone, I am writing a program to perform backup operations using the VB scripting File System Object to copy to removable media storage devices. The backup operation works fine, but when we attempt to remove the backup device, we often get a "Delayed Write Failed" error message, indicating that data was cached and the copy was not actually finished before device removal. The problem now is how can we guarantee that all data is...
4
2893
by: Heiko Selber | last post by:
I am trying to find out (using Python under windows) the name of a CD that is currently in the drive specified by a path name. And while I am at it, I'd also like to know whether the specified drive contains a CD at all, and whether the drive is actually a CD drive. AFAIK, Python doesn't provide a way to do it, and a search in the web yielded only soutions for Linux. Can anyone show me a solution that works with windoze?
10
3403
by: Virginia | last post by:
We have a product that runs on Oracle. The version of Oracle I'm working with is 8.1.7. I should also note that I'm relatively new to Oracle. I'm troubleshooting one particular database that is having performance problems when we try to run various quireies and peform inserts or updates. Unfortunately this particular product "requires" that "OPTIMIZER_MODE = RULE".
1
451
by: Cliff Liao | last post by:
Hi all, I am trying to install the .NET framework 1.1 runtime package on Windows 2000 SP4. While the installation starts well, I get the following message box during the installation process : Please insert the disk : Microsoft .NET Framework (English) : OK Cancel Pressing the OK button will check the floppy drive for a disk and
0
2231
by: Ryan | last post by:
I'm writing a utility that needs to be aware of media (CD, DVD, Zip disk, usb stick, etc) insertions and removals. Which seems to be more of a problem than I original imagined. I can't use any auto-run features because this is actually running on Windows XP Embedded... so that's the first thing to be aware of. Using WM_DEVICECHANGE works about half the time...that is, it works when a DVD or CD is inserted, but it does not work for Zip...
3
5702
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...
0
1053
by: Allen | last post by:
Dim DiskMO As New ManagementObject("win32_logicaldisk.DeviceID=""" & sDrive & """") Then using DiskMO("DriveType") Case DRIVE_TYPES_REMOVABLE snip...
3
3888
by: Mike Joyce | last post by:
I am trying to write a portable script that will find removable media, such as compact flash, sd card, usb, etc. drive and then upload files from the media. I want this to be portable so that I can write and maintain one program for both Linux and Windows. Each platform uses different functions so even if I could find two platform dependent functions that would be fine. Basically, I would like to avoid checking fixed disks if possible. If...
4
2902
by: Per Juul Larsen | last post by:
Hi my VB program must always start from a removable disk. In addition, on the removable media to be images of the type *. jpg *. tips. If not the two conditions are present, the programme will end with a message. How do I write this little control function in Visual Basic regards pjl
0
8063
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8003
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
8498
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8478
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
6014
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
3962
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
4025
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1598
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.