This is the mail archive of the
mailing list for the Cygwin project.
Re: How does one find "cygdrive path" in a Win ".bat" file
- From: Fergus <fergus at bonhard dot uklinux dot net>
- To: Cygwin ML <cygwin at cygwin dot com>
- Cc: Fergus <fergus at bonhard dot uklinux dot net>
- Date: Tue, 10 Feb 2009 09:53:10 +0000
- Subject: Re: How does one find "cygdrive path" in a Win ".bat" file
This might not be quite what you are after, but possibly will provide a
starting point. My Cygwin installation is mounted in the root directory
of a portable drive so, depending on where I am, the drive might end up
being D: or F: or G: or M: or ... The lines following are the first few
lines in a .cmd file located at \ that will correctly implement commands
under /bin (or anywhere else under /) because the correct drivename is
correctly identified whether you start the .cmd file (a) from a Command
Prompt (b) using Start -> Run -> .. or (c) by double-clicking in Explorer.
(It's to allow for both (b) and (c) that the rather awkward pair of if()
commands are needed.)
if (%DOS_CMD:~1,1%)==(:) set DN=%DOS_CMD:~0,2%
if (%DOS_CMD:~2,1%)==(:) set DN=%DOS_CMD:~1,2%
More generally, a user's Cygwin installation might be located on a
portable drive under \dir1\dir2\dir3\.. and then in general the startup
command file will need to "know" or "discover" not just the drivename
but the pathname: ie CWD.
NB I have not found a foolproof way of doing this other than by locating
the command file at \dir1\dir2\dir3\.. (i.e. at / with respect to the
Cygwin installation) and this might be too specialised for what you want
to do, but if your quest is more general than this, I think
> you have to rely on external data and heuristics
as earlier suggested.
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html