473,320 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 2262
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***@tangelosoftware.net>
declaimed the following in comp.lang.python:
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.GetDriveType
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.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@bestiaria.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.GetDriveType
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
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...
4
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...
10
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...
1
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 :...
0
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...
3
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...
0
by: Allen | last post by:
Dim DiskMO As New ManagementObject("win32_logicaldisk.DeviceID=""" & sDrive & """") Then using DiskMO("DriveType") Case DRIVE_TYPES_REMOVABLE snip...
3
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...
4
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
0
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...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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....
0
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
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.