Path name conversions, Posix <-> Win32

Guy G. Piggford
Tue Jan 13 12:59:00 GMT 1998

At 10:22 AM 1/13/98 +1300, Mark Hadfield wrote:
>Where can I find command-line utilities for conversion between Cygwin32
>Posix-style and Win32 path names? Eg, a pair of utilities that work like
>bash$ echo //C/foo | win32path
>bash$ echo C:\\foo | posixpath
>I know it's not too difficult to implement this via string substitution in
>awk or bash. (The above examples are real output, produced by a pair of
>Python scripts that I wrote.) What I really want is something that knows
>about Cygwin32 mounts, eg:

Well you can try something like this:

function win32path
    declare file=$1
    file=$( echo $file | sed -e 's,//\(.\),\1:,' \
		`mount | sed -n 's,\([^ ]*\) *\(/[^ ]*\).*,-e s~^\2~\1~,p'` \
		-e 's,/,\\,g' \
		-e 's,:\([^\\]\),:\\\1,g')
    echo $file

It doesn't like getting spaces in path names since it only acts upon $1,
but other than that it doesn't do too badly.  I'd be interested in any
improvements though, I'm sure that it's probably simpler to do in perl, but
I don't know it well enough.

I've never found a need for the posixpath version so I don't have a canned
one handy.


For help on using this list (especially unsubscribing), send a message to
"" with one line of text: "help".

More information about the Cygwin mailing list