Results 1 to 11 of 11

Thread: Directpry

  1. #1
    Join Date
    Mar 2006
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Directpry :: How to check existence of directory...???

    How to check whether given directory is existing or not?

  2. #2
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Directpry

    Try QDir::exists()

  3. #3
    Join Date
    Mar 2006
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Re: Directpry

    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???

  4. #4
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Directpry

    Quote Originally Posted by shailesh
    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:
    Qt Code:
    1. QDir("C:\Shailesh").exists()
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Mar 2006
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Directpry

    Thanks very much man... Its working...

  6. #6
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Directpry

    Quote Originally Posted by Dark_Tower
    Have you tried:
    Qt Code:
    1. QDir("C:\Shailesh").exists()
    To copy to clipboard, switch view to plain text mode 
    Or, rather:
    Qt Code:
    1. QDir("C:\\Shailesh").exists()
    To copy to clipboard, switch view to plain text mode 
    Save yourself some pain. Learn C++ before learning Qt.

  7. #7
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Directpry

    Quote Originally Posted by Chicken Blood Machine
    Or, rather:
    Qt Code:
    1. QDir("C:\\Shailesh").exists()
    To copy to clipboard, switch view to plain text mode 
    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?

  8. #8
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Directpry

    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 '\\'.
    Save yourself some pain. Learn C++ before learning Qt.

  9. #9
    Join Date
    Apr 2006
    Location
    Minsk, Belarus
    Posts
    23
    Thanks
    3
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Directpry

    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.

  10. #10
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Directpry

    Quote Originally Posted by Lemming
    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.
    Save yourself some pain. Learn C++ before learning Qt.

  11. #11
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Directpry

    Thanks both, now I've got it clear!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.