Cygwin Path and Windows Path Conversion

By Xah Lee. Date: . Last updated: .

The filename path issue between unix and Windows can be complex.

Read: .

In general, when you are in Cygwin, always use unix-style path, for example, /something/something. When you need C:/Users/joe/notes.txt, use /cygdrive/c/Users/joe/notes.txt.

For example, when i started to use Cygwin, had a problem that caused me few hours. I have a python program that makes a system call of imagemagick's convert command. This all works fine in OS X. When trying to run it on Windows with Cygwin, i simply changed the input paths from /Users/xah/web/ to C:/Users/xah/web/. This does not work. After some hours of looking, here's some detail:

When in Cygwin terminal, the following does not work:

# cygwin complains cannot find the second file
# convert: unable to open image `/Users/xah/x2.jpg': No such file or directory.
convert C:/Users/xah/x.png C:/Users/xah/x2.jpg
convert "C:/Users/xah/x.png" "C:/Users/xah/x2.jpg"

# complains cannot find the first file
convert /Users/xah/x.png ~/x2.jpg

convert "C:/Users/xah/x.png" /Users/xah/x2.jpg
convert /Users/xah/x.png /Users/xah/x2.jpg
convert /Users/xah/x.png x2.jpg

The following creates the image, but the result image is bad.

# creates image, but bad img data
convert C:/Users/xah/x.png "C:\Users\xah\x2.jpg"
convert C:/Users/xah/x.png C:\\Users\\xah\\x2.jpg

# this one creates image in the in current dir as Usersxahx2.jpg
convert C:/Users/xah/x.png C:\Users\xah\x2.jpg

The following works:

convert "C:/Users/xah/x.png" ~/x2.jpg
convert C:/Users/xah/x.png ~/x2.jpg
convert C:/Users/xah/x.png /cygdrive/c/Users/xah/x2.jpg
convert /cygdrive/c/Users/xah/x.png /cygdrive/c/Users/xah/x2.jpg

Here's some lesson learned: