0

I need to determine that a string entered by a user is OK to create a file with that name. My application is built on Qt and runs on Windows and Mac OS.

I've found a check function in boost.filesystem, namely native(). The documentation says, 'Returns true for names considered valid by the operating system's native file systems.' Sounds like what I need, but the function doesn't work properly and returns false always. I've tried both back and forward slashes in the path, and tested the function with both existing and non-existing paths—all these tests failed on Windows. Thanks to chris (see a comment below) who pointed that the function may be intentionally broken (I tend to agree with that).

So the question is: how to achieve what I need?

Alexander Dunaev
  • 980
  • 1
  • 15
  • 40
  • Could you give a sample input that fails? – chris Jun 03 '13 at 03:34
  • Sure. D:\Work\cpptest —that directory exists on my machine but the native() call returns false for it. (Of course I have escaped the back slashes in my code :-) .) – Alexander Dunaev Jun 03 '13 at 03:36
  • Perhaps it's the fact that they're holdovers from version 1. The header in 1.53 says *"These functions are holdovers from version 1. It isn't clear they have much usefulness, or how to generalize them for later versions."* – chris Jun 03 '13 at 03:41
  • Why do it at all? There are so many ways for a file creation to fail, and most of them cannot be checked in advance. A two-stage check would only confuse the users. The fact that the boost function is broken should also hint of something. – n. m. could be an AI Jun 03 '13 at 05:02
  • Because I want to warn the user if a path was obviously invalid. – Alexander Dunaev Jun 03 '13 at 05:14
  • Couldn't you use a try-catch block when you go to open the file, and catch the exception that's thrown if the string is wrong.? – tinstaafl Jun 03 '13 at 06:42
  • I could but that's not what I want. I don't want to create a file before the actuall data processing begins. – Alexander Dunaev Jun 03 '13 at 07:14

0 Answers0