473,729 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to find the drive in python/cygwin?

Hello:

I'm running python under cygwin and need to find the drive letter.
Cygwin has a way of calling my drives by a name relative to the Cygwin
directory, so I get things like /home/user rather than
/cygdrive/g/cygwin/home/usr, etc. How can I find the letter of the
drive, or in the above example, the letter 'g'?

My program needs to run on an external media that comes with Cygwin on
it. I have no control over what drive is assigned to that media, but
for some reason, I do need to know the letter.

Please help!

Thanks,

Mayer

Jul 19 '05 #1
9 3541
On 26 Apr 2005 11:29:26 -0700, Mayer <gm****@cs.bgu. ac.il> wrote:
Hello:

I'm running python under cygwin and need to find the drive letter.
Cygwin has a way of calling my drives by a name relative to the Cygwin
directory, so I get things like /home/user rather than
/cygdrive/g/cygwin/home/usr, etc. How can I find the letter of the
drive, or in the above example, the letter 'g'?
Generally, drive N gets mapped to /cygdrive/n/ but you could call the
'mount' command and parse the output to see what drive letter got
assigned to a given path. On my system, mount returns:

$ mount
C:\cygwin\usr\X 11R6\lib\X11\fo nts on /usr/X11R6/lib/X11/fonts type
system (binmode)
C:\cygwin\bin on /usr/bin type system (binmode)
C:\cygwin\lib on /usr/lib type system (binmode)
C:\cygwin on / type system (binmode)
c: on /cygdrive/c type user (binmode,noumou nt)
d: on /cygdrive/d type user (binmode,noumou nt)
g: on /cygdrive/g type user (binmode,noumou nt)
x: on /cygdrive/x type user (binmode,noumou nt)
z: on /cygdrive/z type user (binmode,noumou nt)
My program needs to run on an external media that comes with Cygwin on
it. I have no control over what drive is assigned to that media, but
for some reason, I do need to know the letter.


Why?

--
Kristian

kristian.zoerho ff(AT)gmail.com
zoerhoff(AT)fre eshell.org
Jul 19 '05 #2

How about doing "cygpath -w /home/user" and picking the drive letter?

Raghu.

Jul 19 '05 #3
Forwarding to list, as you forgot to Reply-all (Don't worry, we all do
it at least once!).

---------- Forwarded message ----------
From: Mayer Goldberg <gm****@littl e-lisper.org>
Date: Apr 26, 2005 3:01 PM
Subject: Re: how to find the drive in python/cygwin?
To: Kristian Zoerhoff <kr************ ***@gmail.com>
Dear Kristian:

Thanks for the very fast reply! I wasn't thinking of the mount command
-- this is really the correct way to think about my problem.
My program needs to run on an external media that comes with Cygwin on
it. I have no control over what drive is assigned to that media, but
for some reason, I do need to know the letter.


Why?


Basically this has to do with moving around: I use different computers
throughout the day, and need to carry with me a sane and productive
computing environment. Rebooting to linux is not an option for me, so I
need a Windows solution. I found it in the form of a 40G pocket hard
drive with a USB connection. I plug in the connection, go to my software
subdirectory and run what I need. I have a mixture of Unix and Windows
programs, and often I have to run a Windows program instead of a unix
program (for example, I run miktex instead of the tetex that comes with
cygwin). The Windows utilities need to be passed arguments in DOS
format, i.e., something like G:\FOO\foo.dll. Cygwin is only one specific
application I use, so I didn't install everything under the / (which
would have solved many problems for me!). As a result, I need to know
the drive letter.

Thanks again,

Mayer
--
Kristian

kristian.zoerho ff(AT)gmail.com
zoerhoff(AT)fre eshell.org
Jul 19 '05 #4
Hi All--
Use win32api to find drives:

====cut here====
#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import os.path
import win32api
import sys
def findAllDrives() :
Drives=[]
print "Searching for drives..."
drives=win32api .GetLogicalDriv eStrings().spli t(":")
for i in drives:
dr=i[-1].lower()
if dr.isalpha():
dr+=":\\"
inf=None
try:
inf=win32api.Ge tVolumeInformat ion(dr)
except:
pass # Removable drive, not ready
# You'll still get the drive letter, but inf will be None
Drives.append([dr,inf])
return Drives

if __name__=="__ma in__":
drives=findAllD rives()
for i in drives:
print i[0],i[1]

====cut here====

Metta,
Ivan
----------------------------------------------
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/worksh...oceedings.html
Army Signal Corps: Cu Chi, Class of '70
Author: Teach Yourself Python in 24 Hours
Jul 19 '05 #5
Ivan,

On Tue, Apr 26, 2005 at 07:02:48PM -0600, Ivan Van Laningham wrote:
Use win32api to find drives:

====cut here====
#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import os.path
import win32api
[snip]


AFAICT, the win32api module has not been ported to Cygwin Python.

Jason

--
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6
Jul 19 '05 #6
Hi All--

Jason Tishler wrote:

Ivan,

On Tue, Apr 26, 2005 at 07:02:48PM -0600, Ivan Van Laningham wrote:
Use win32api to find drives:

====cut here====
#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import os.path
import win32api
[snip]


AFAICT, the win32api module has not been ported to Cygwin Python.


I'm not running Cygwin, but Uwin. I installed regular Python:
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright" , "credits" or "license" for more information.
^Z

with the win32api that matched. I have no trouble running it. Is there
some reason to prefer a Python compiled by the Cygwin tools?

Metta,
Ivan
----------------------------------------------
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/worksh...oceedings.html
Army Signal Corps: Cu Chi, Class of '70
Author: Teach Yourself Python in 24 Hours
Jul 19 '05 #7
Ivan,

On Sat, Apr 30, 2005 at 07:29:32AM -0600, Ivan Van Laningham wrote:
Jason Tishler wrote:
On Tue, Apr 26, 2005 at 07:02:48PM -0600, Ivan Van Laningham wrote:
Use win32api to find drives:

====cut here====
#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import os.path
import win32api
[snip]


AFAICT, the win32api module has not been ported to Cygwin Python.


I'm not running Cygwin, but Uwin. I installed regular Python:

Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright" , "credits" or "license" for more information.
^Z


with the win32api that matched. I have no trouble running it. Is
there some reason to prefer a Python compiled by the Cygwin tools?


It depends on your needs. If you are looking for a more Unix-like
Python, then the Cygwin version would probably be better. If
Windows-like, then the native Windows version would probably be better.

The OP seem to be interested in a Cygwin Python solution -- not a
Windows one. So, I was just clarifying that the win32api module is not
supported under Cygwin Python.

Jason

--
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6
Jul 19 '05 #8
Hi All--

Jason Tishler wrote:

Ivan,

It depends on your needs. If you are looking for a more Unix-like
Python, then the Cygwin version would probably be better. If
Windows-like, then the native Windows version would probably be better.

The OP seem to be interested in a Cygwin Python solution -- not a
Windows one. So, I was just clarifying that the win32api module is not
supported under Cygwin Python.


Could you clarify? I always thought that the only thing really
different were the default path assumptions--/ instead of \, and so
on--rather than anything substantive. I try to use os.path.sep() and
os.path.join(), etc.

What else could bite me? ;-)

Metta,
Ivan
----------------------------------------------
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/worksh...oceedings.html
Army Signal Corps: Cu Chi, Class of '70
Author: Teach Yourself Python in 24 Hours
Jul 19 '05 #9
Ivan,

On Sat, Apr 30, 2005 at 08:44:55AM -0600, Ivan Van Laningham wrote:
Jason Tishler wrote:
I was just clarifying that the win32api module is not supported
under Cygwin Python.


Could you clarify? I always thought that the only thing really
different were the default path assumptions--/ instead of \, and so
on--rather than anything substantive. I try to use os.path.sep() and
os.path.join(), etc.

What else could bite me? ;-)


Not much -- at least not too hard. :,) Anyway, only the low level stuff
would be different: Posix versus Win32, shared extensions, etc. The
high level stuff should be the same -- isn't Python just Python. :,)

Jason

--
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6
Jul 19 '05 #10

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

Similar topics

0
1645
by: Jari Aalto+usenet | last post by:
Hi, Where I can specify more linking search directories for a Python module that makes a gcc build? Setting the LD_LIBRARY_PATH on command line does not seem to propagate to the linker. Jari root@w2kpicasso:/usr/share/site-python/xmldiff-0.6.3# echo $LD_LIBRARY_PATH
2
5796
by: Jörg Maier | last post by:
Hey guys, i have a big problem using Tkinter and pexpect in cygwin. i try to program an winscp-like rsync Program for all posix Platforms (linux, macosx, cygwin). i got a class SslConnection with a method listDirectory that gives back a list of an remote directory using pexpect. this method works in linux, it works in cygwin-python from command-line, but invoked in an Tkinter-Program i got the strange Exception:...
4
2425
by: Andreou Giannis | last post by:
Allthough it is possible to build modules in Python2.3.3 and distutils with cygwin, by running: setup.py build --compiler=cygwin (after i created the libpython23.a) running: setup.py install afterwards, complains about not building with msvs v.6, since my Python distribution is built with it.
2
14359
by: Jorgen Grahn | last post by:
I couldn't think of a good solution, and it's hard to Google for... I write python command-line programs under Win2k, and I use the bash shell from Cygwin. I cannot use Cygwin's python package because of a binary module which has to be compiled with Visual C 6. My scripts start with a '#!/usr/bin/env python' shebang, as God intended. Now, I assume I can make cmd.exe run foo.py by asociating *.py with the python interpreter.
3
7368
by: RMJ | last post by:
After installing Enthought's python and typing 'python' from within cygwin the program hangs with no output. I do not remember this being the case with earlier versions of Enthought python. Is this version not compatible with cygwin? Or, is there some configuration file that needs changing? It does run successfully with 'python somecode.py' -but without printing out intermediate results. Thanks! -Roger Jones
0
2031
by: Adam McCarthy | last post by:
I'm trying to get a cross compiler working for arm-wince-pe. This is the output for the primes Pyrex example. If I compile simple Hello, World's etc, it works fine, but for some reason Python libraries/headers seem to produce this. I have libpython2.3.a in /usr/local/lib/gcc-lib/arm-wince-pe/3.3.3/../../../../arm-wince-pe/lib/ and /usr/lib/python2.3/config. I've checked it using arm-wince-pe-objdump. I also extracted it with...
66
5482
by: Srijit Kumar Bhadra | last post by:
Is there any specific reason for not using MinGW to build the official distribution of Python for Win32? A quick Google search did not reveal the answer to my question. If a link is available, please post it. Best Regards, Srijit
9
2493
by: Endless Story | last post by:
My last version of Python was 2.4, running smoothly on XP with path c: \Python24 - no need even to include this path in PATH; everything worked as it's supposed to at the command line. Just installed Python 2.5, after uninstalling 2.4 (and also 2.3 which had lingered). Now if I open a shell in Windows Python is not available! Here are the symptoms: - If I open a shell using "Command line here" with XP Powertools, then enter "python"...
7
409
by: Anton Mellit | last post by:
Hi, I am working on a Pari-Python module (see about GP/PARI at http://pari.math.u-bordeaux.fr/). Similar project was started by Stefane Fermigier 12 years ago (you can find a post about it on this newsgroup). You can see some screenshots on my blog (http:// mellit.wordpress.com/2007/10/28/pari-python/). I reproduce the text on my blog here. I finished some working version of the pari-python module. I tried to
0
8927
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
9428
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
9289
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...
0
9156
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8159
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...
0
6026
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4798
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3242
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
3
2166
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.