Is it safe to convert Windows file paths to Unix file paths with a simple replace?
Posted
by
MxyL
on Programmers
See other posts from Programmers
or by MxyL
Published on 2014-06-16T16:26:57Z
Indexed on
2014/08/22
4:27 UTC
Read the original article
Hit count: 276
java
|file-systems
So for example say I had it so that all of my files will be transferred from a windows machine to a unix machine as such: C:\test\myFile.txt
to {somewhere}/test/myFile.txt
(drive letter is irrelevant at this point).
Currently, our utility library that we wrote ourselves provides a method that does a simple replace of all back slashes with forward slashes:
public String normalizePath(String path) {
return path.replaceAll("\\", "/");
}
Slashes are reserved and cannot be part of a file name, so the directory structure should be preserved. However, I'm not sure if there are other complications between windows and unix paths that I may need to worry about (eg: non-ascii names, etc)
© Programmers or respective owner