Question

Im trying to convert the file paths to/from Linux and Windows on Windows Machine.

unix path to windows works fine.

$ cygpath -w /cygdrive/c/CYGWIN/CYGBuild/build.mak
C:\CYGWIN\CYGBuild\build.mak

But windows path to Linux gives wrong output. i.e Missing '/' and also cygdrive

$ cygpath -u c:\cygwin\cygbuild\build.mak
c:cygwincygbuildbuild.mak

Anyone faced this issue?? Share your experience.

Thanks

Was it helpful?

Solution

I got answer for this question.

cygpath -u 'c:\cygwin\cygbuild\build.mak'

i.e path should be given in single quotation.

OTHER TIPS

Actually as far as I know; you need forward slashes in paths used in cygwin. Single quotations help in cases where there are spaces (and my guess in this case; using backslashes instead of forward slashes) in the path. Otherwise backslashes are like escape characters, while spaces (although not in your case) require escape characters themselves. So quoting the path tends to eliminate such hassles.

Here are links that help me understand this:

  • This opencv (using cygwin) tutorial, page 4, where there's an example of paths used, with and without quotes, indicating when one might need them.
  • Also this is very useful; a list of Cygwin's FAQs, including how to deal with spaces (or in this case, backslashes in the path where adding quotes would help).

cygpath's -m option is probably the easiest solution. Windows software generally accepts / as well as \. (There may be a few exceptions, but the development tools I work with have all been fine with it.)

$ cygpath -m /cygdrive/c/CYGWIN/CYGBuild/build.mak

C:/Cygwin/CYGBuild/build.mak

No one seems to have explain why, we here is an explanation.

Cygpath will accept slashes, and back-slashes: c:/cygwin/cygbuild/build.mak c:\cygwin\cygbuild\build.mak. However the shell will interpret the back-slashes, therefore you need to stop the shell from interpreting the back-slashes.

You can stop the shell from interpreting back-slashes, in arguments, by preceding them with a back-slash, or by quoting (with single quotes): c:\\cygwin\\cygbuild\\build.mak or 'c:\cygwin\cygbuild\build.mak'.

Double quotes will not help in this case. Double quotes stops argument breaking on space, but does not stop interpretation of escapes (\), or dollar ($) expansion.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top