ataylor Posted April 1, 2015 Posted April 1, 2015 Running windows 8.1, my "USERPROFILE" environment variable is "C:\Users\User". Note the lack of trailing slash as is common with paths in Windows. Unigine::Widgets::DialogFile dialog=new Unigine::Widgets::DialogFile("Open"); dialog.setPath(getenv("USERPROFILE")); This will open a dialog file with the path set to "C:\Users", not "C:\Users\User" the way I would expect. Unigine::Widgets::DialogFile dialog=new Unigine::Widgets::DialogFile("Open"); dialog.setPath(getenv("USERPROFILE")+"/"); This opens to the correct path.
unclebob Posted April 3, 2015 Posted April 3, 2015 Thanks, Adam! That's because setPath("test/test") could be pointing to a file or a directory and we need a way to distinguish between these two cases, so we decided that directories will use additional trailing slash. Not a bug. :)
ataylor Posted April 6, 2015 Author Posted April 6, 2015 Hi unclebob. Thanks for your reply. I understand that this is a design decision and not strictly a bug, but I think there is some room for improvement. Take example of setPath("foo/bar"). I believe all modern filesystems forbid having a normal file and a directory with the same name in the same location, so we never have a situation where we truly don't know what 'bar' refers to. If 'bar' exists, we can ask OS if it is a normal file or a directory and act accordingly: If 'bar' is a directory, use it as part of path. If 'bar' is a normal file, ignore it and set path only to 'foo'. I would expect this all to be handled by setPath. With a function name & signature such as setPath(string str), I feel it is implied that the entirety of str will be used as the path, rather than only parsing through to final slash -- especially since the trailing slash requirement is neither obvious nor mentioned in the documentation for setPath. Also, given that file paths often traditionally DO refer to directories without using trailing slashes (including usages like "official" environment variables), I feel it would be best to be compatible with these paths without requiring the user to append a slash. Thanks for your consideration.
unclebob Posted April 8, 2015 Posted April 8, 2015 Thanks for explanation, Adam. You have a good point here, I'll ask our devs if they could add this.
Recommended Posts