PDA

View Full Version : Directpry



shailesh
10th April 2006, 10:18
How to check whether given directory is existing or not?

Dark_Tower
10th April 2006, 10:22
Try QDir::exists() :rolleyes:

shailesh
10th April 2006, 10:44
Thanks for your reply man.

Ya man... i know abt this method of QDir. But first of all we have to create an object of QDir with some argument.

Now i have a string say c:\Shailesh and i want to check whether this directory exists or not???

Dark_Tower
10th April 2006, 10:49
Thanks for your reply man.

Ya man... i know abt this method of QDir. But first of all we have to create an object of QDir with some argument.

Now i have a string say c:\Shailesh and i want to check whether this directory exists or not???

Have you tried:

QDir("C:\Shailesh").exists()

shailesh
10th April 2006, 11:03
Thanks very much man... Its working...

Chicken Blood Machine
10th April 2006, 18:18
Have you tried:

QDir("C:\Shailesh").exists()


Or, rather:

QDir("C:\\Shailesh").exists()
;)

Dark_Tower
10th April 2006, 18:31
Or, rather:

QDir("C:\\Shailesh").exists()
;)

Sorry Chicken Blood Machine for my ignorance, but i've never seen accessing a directory with double dashed bar. Can you explain me please if exists any difference between accessing with one dashed bar or two?

Chicken Blood Machine
10th April 2006, 19:03
The backslash '\' is a special escape charater, used to mark no-printable characters like tab ('\t'), newline ('\n'), etc . Therefore you can't use '\' on its own. You must use '\\'.

Lemming
10th April 2006, 19:04
Actually, it is better to access the directories like this: "C:/MyDir/MySubdir" (using slashes instead of backslashes) with QT, especially if you are working on a code that is intended to work on some platforms other than win.

The difference between "\\" and "\" is that "\" symbol in C++ string constants marks the beginning of the escape sequence (like "\n" for newline). Therefore, if you wish to have a "\" symbol in your string you have to use a "\\" escape sequence.

Chicken Blood Machine
11th April 2006, 07:19
Actually, it is better to access the directories like this: "C:/MyDir/MySubdir"

Trust me "C:/MyDir/MySubdir" will work on no other platform than Windows!

Ideally, you will avoid absolute paths altogether and yes, it is better to use the forward slash for Qt code.

Dark_Tower
11th April 2006, 10:08
Thanks both, now I've got it clear!