Results 1 to 3 of 3

Thread: Trouble with proper syntax for directorys

  1. #1
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Trouble with proper syntax for directorys

    What I'm trying to accomplish is have my application check to see if some directories exist

    if ttm does not make it if it does then go on to clients if it don't exist then make it and if its there continue to clientdir and campaigndir

    this is the current solution im currently trying to figure out..
    Qt Code:
    1. QDir ttmDir("/ttm");
    2. QDir clientsDir("/ttm/clients");
    3. QDir clientDir("/ttm/clients/" + clientID.toInt());
    4. QDir campaignDir(campaignID);
    5.  
    6.  
    7. //Check to see if "/ttm" is there or not if not make it..
    8. if(!ttmDir.exists())
    9. {
    10. QDir().mkdir("/ttm");
    11. qDebug() << "ttm didnt exist creating it";
    12. }
    13. if (ttmDir.exists())
    14. {
    15. qDebug() << "ttm exist so lets check clientsDir";
    16.  
    17. if(!clientsDir.exists())
    18. {
    19. qDebug() << "clientsDir does not exist creating it...";
    20. QDir().mkdir("/ttm/clients");
    21. }else
    22. {
    23. qDebug() << "clientsDir exist lets check clientDir";
    24. }
    25.  
    26. }
    27. if (!clientDir.exists())
    28. {
    29. qDebug() << "clientDir does not exist creating it...";
    30. QDir().mkdir("/ttm/clients/" + clientID.toInt());
    31.  
    32. }
    To copy to clipboard, switch view to plain text mode 

    "QDir().mkdir("/ttm/clients/" + clientID.toInt());" = 16

    but it will not create the folder 16 within /ttm/clients/ ie: "/ttm/clients/16"

    nothing I do will make it work i checked file permissions and even tried using system(""); to accomplish this task but still will not work..

    does anyone have any suggestions?
    Last edited by prophet0; 21st February 2012 at 21:29.

  2. #2
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Trouble with proper syntax for directorys

    A better way to test if a directory exists might be
    yourDir.cd(dirName)
    If it returns true, you are sure it exists AND is readable.

    Furthermore, you are using mkdir() as a static function which it isn't.

  3. #3
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Trouble with proper syntax for directorys

    thanks i fixed it with the following code this is just a rough draft i need to make it all automated but here is my code for anyone else looking for something close to this

    Qt Code:
    1. QDir ttmDir("/ttm");
    2. QDir clientsDir("/ttm/clients");
    3. QDir clientDir("/ttm/clients/" + clientID);
    4. QString clientString = "/ttm/clients/" + clientID;
    5. QDir campaignDir("/ttm/clients/" + clientID + QDir::separator() + campaignID);
    6. QString campaignString = "/ttm/clients/" + clientID + QDir::separator() + campaignID;
    7.  
    8.  
    9. //Check to see if "/ttm" is there or not if not make it..
    10. if(!ttmDir.exists())
    11. {
    12. QDir().mkdir("/ttm");
    13. QDir().setCurrent("/ttm/");
    14. qDebug() << "ttm didnt exist creating it";
    15. ui->progressBar->setValue(40);
    16.  
    17. }
    18. if (ttmDir.exists())
    19. {
    20. qDebug() << "ttm exist so lets check clientsDir";
    21.  
    22. if(!clientsDir.exists())
    23. {
    24. qDebug() << "clientsDir does not exist creating it...";
    25. QDir().mkdir("/ttm/clients");
    26. QDir().setCurrent("/ttm/clients/");
    27. ui->progressBar->setValue(45);
    28. }else
    29. {
    30. qDebug() << "clientsDir exist lets check clientDir";
    31. QDir().setCurrent("/ttm/clients/");
    32. }
    33.  
    34. }
    35. if (!clientDir.exists())
    36. {
    37. qDebug() << "clientDir does not exist creating it...";
    38. QDir().mkdir(clientString);
    39. QDir().setCurrent(clientString);
    40. ui->progressBar->setValue(50);
    41.  
    42. }else
    43. {
    44. qDebug() << clientString;
    45. qDebug() << "clientDir exists lets check campaignDir";
    46. ui->progressBar->setValue(55);
    47. }
    48. if(!campaignDir.exists())
    49. {
    50. qDebug() << "campaignDir does not exist creating it...";
    51. QDir().mkdir(campaignString);
    52. QDir().setCurrent(campaignString);
    53. ui->progressBar->setValue(60);
    54. }else
    55. {
    56. qDebug() << "campaignDir exists lets download the content now...";
    57. ui->progressBar->setValue(65);
    58. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Proper way to use qmake and moc?
    By mossen in forum Newbie
    Replies: 1
    Last Post: 6th May 2011, 02:52
  2. proper use of QList?
    By jhowland in forum Qt Programming
    Replies: 3
    Last Post: 13th September 2010, 14:57
  3. Regarding syntax
    By Yayati.Ekbote in forum Qt Programming
    Replies: 3
    Last Post: 27th January 2010, 14:15
  4. Odd Syntax
    By acxdotfm in forum Qt Programming
    Replies: 2
    Last Post: 24th October 2008, 20:23
  5. Proper way to #include Qt?
    By pherthyl in forum Qt Programming
    Replies: 1
    Last Post: 11th August 2006, 02:15

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.