Friday, July 31, 2009

Perl: File::Path::mkpath results in error: "No such file or directory"

I was running a Perl script that came with ACE to generate doxygen documentation. When trying to run it on Windows via Cygwin, I got the following mysterious error:
... : No such file or directory at line …

The line producing this error was a call to File::Path::mkpath. There was absolutely no help out there, because the only thing I could find on this error was in the Perl documentation, which only said that I should make sure the filename isn’t too long for Windows. It wasn’t.

So, after debugging this for half a day (!!!), I finally discovered that it was being caused by CRLF line endings in Windows. A portion of the path being sent to the mkpath function was being read from a file. That file had CRLF line endings, and Cygwin was treating everything in “unix” mode. So the path had the left over ‘\r’ character, which is invalid in a path name.

The solution:
set the PERLIO environment variable to “crlf”. I just added that to my .bashrc.

1 comment:

Unknown said...

If your file path is too long and you want to copy that file then use Long Path Tool. Its worth using it.