How to check if a directory exists using QDir?

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

QDir("a/b").exists();

QDir().exists("a/b");

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.

 

Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:
Posted in

Comments are closed, but trackbacks and pingbacks are open.