Brendon Costa
2006-06-15 00:23:22 UTC
Hi All,
I was wondering if there is an existing way to convert a MSYS
path/filename into a windows path/filename?
MSYS will usually convert automatically for me, but I have a few
arguments like -I/c/dev/BJC/include that will not because they are
prefixed with the -I (Note am using MSVC not gcc for this one). This
is being done in a script so I have the luxury of scripting a
conversion function.
Note: I have to be able to convert both directory names and file
names. I was looking at a few methods.
1) Convert /c/ to c:/
Problems:
* Does not work with relative paths that may exist in the MSYS fstab
file. E.g. I have /usr/local mapped to C:\msys_local if the relative
path resulted into this place, then the above method would fail.
* Need to add for every drive not just /c/ as i have a lot of
development code on a network drive /x/ etc.
2) Remove the filename from the end of the identifier if one exists
and then do a cd into the directory and then pwd -W to get the name.
Problems:
* This will not always work because sometimes the file/directory
structure does not yet exist and will be created by the command so the
cd fails.
3) Break the string into a space separated list by substituting all
'/' characters with space characters and iterating over the list in a
for loop. For each item I attempt to cd into it. If the cd fails then
the directory does not exist. Get the pwd -W of the directory before
the one that failed, and then add the rest of the items to then then
of the pwd -W result separated by '/' characters.
Problems:
* A bit complicated. Also will not keep relative paths that can be
kept. I.e. if I am in /c/dev/BJC/blah and need to convert
"../../thing" from a MSYS path to a windows path, then the the
resulting windows path would be "C:/dev/thing", but it could be
"../../thing"
Number 3 seems like a reasonable option to me, but before I implement
it I thought I would ask if there is a standard way of achieving this
that already exists or any recommendations people would have?
By the way I had a quick look in the FAQ section of the Wiki and did
not find any items for this. Maybe it would be worth adding this as a
FAQ (Though not sure how "Frequent" this question would be)?
Thanks,
Brendon.
I was wondering if there is an existing way to convert a MSYS
path/filename into a windows path/filename?
MSYS will usually convert automatically for me, but I have a few
arguments like -I/c/dev/BJC/include that will not because they are
prefixed with the -I (Note am using MSVC not gcc for this one). This
is being done in a script so I have the luxury of scripting a
conversion function.
Note: I have to be able to convert both directory names and file
names. I was looking at a few methods.
1) Convert /c/ to c:/
Problems:
* Does not work with relative paths that may exist in the MSYS fstab
file. E.g. I have /usr/local mapped to C:\msys_local if the relative
path resulted into this place, then the above method would fail.
* Need to add for every drive not just /c/ as i have a lot of
development code on a network drive /x/ etc.
2) Remove the filename from the end of the identifier if one exists
and then do a cd into the directory and then pwd -W to get the name.
Problems:
* This will not always work because sometimes the file/directory
structure does not yet exist and will be created by the command so the
cd fails.
3) Break the string into a space separated list by substituting all
'/' characters with space characters and iterating over the list in a
for loop. For each item I attempt to cd into it. If the cd fails then
the directory does not exist. Get the pwd -W of the directory before
the one that failed, and then add the rest of the items to then then
of the pwd -W result separated by '/' characters.
Problems:
* A bit complicated. Also will not keep relative paths that can be
kept. I.e. if I am in /c/dev/BJC/blah and need to convert
"../../thing" from a MSYS path to a windows path, then the the
resulting windows path would be "C:/dev/thing", but it could be
"../../thing"
Number 3 seems like a reasonable option to me, but before I implement
it I thought I would ask if there is a standard way of achieving this
that already exists or any recommendations people would have?
By the way I had a quick look in the FAQ section of the Wiki and did
not find any items for this. Maybe it would be worth adding this as a
FAQ (Though not sure how "Frequent" this question would be)?
Thanks,
Brendon.