How to check if a directory exists using QDir?

QDir has two versions of exists function that check if a folder exists:



There is a little difference between the two functions. If a is a directory and b is a sub-directory under a, both functions return true; If a is a folder and b is an ordinary file in a,  QDir(“a/b”).exists() returns false but QDir().exists(“a/b”) returns true. So, to check if a directory exists, you’d better use QDir(“a/b”).exists(). Note that the path specified as the parameter of exists function is relative to the folder of that QDir, not the working directory. So QDir(“a/b”).exists(“a/b”) is actually checking if the folder/file “a/b/a/b” exists.


Posted in

Comments are closed, but trackbacks and pingbacks are open.