Results 1 to 3 of 3

Thread: DisplayTree Structure of the path

  1. #1
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default DisplayTree Structure of the path

    Hi all

    Here there is a pr[B]ogram which is copying source to destination but by using this logic i want it displays all the items of the selectedpath in a tree structured form.

    Qt Code:
    1. #include <qfiledialog.h>
    2. #include <qstring.h>
    3. #include<qlabel.h>
    4. #include<qstringlist.h>
    5. #include<qprogressbar.h>
    6. #include<qfile.h>
    7. #include<qdir.h>
    8. #include<stdio.h>
    9. #include <qfileinfo.h>
    10. #include<qmessagebox.h>
    11. #include <qapplication.h>
    12.  
    13. void Form1::init()
    14. {
    15. m_totalsteps= 1;
    16. progress->setTotalSteps(4000);
    17.  
    18. }
    19.  
    20. void Form1::copydata()
    21. {
    22. CopyAllFilesandFolders(m_StrSource,m_StrDestination);
    23.  
    24. }
    25.  
    26. void Form1::CopyAllFilesandFolders(QString source,QString destination)
    27. {
    28. QDir dir(source);
    29. QDir dir1;
    30. QString sourceFilePath;
    31. const QFileInfoList * dirs=dir.entryInfoList();
    32. {
    33. if(dirs)
    34.  
    35. {
    36. QFileInfoListIterator it(*dirs);
    37. QFileInfo * fileInfo;
    38. while(fileInfo=it.current())
    39. {
    40. ++it;
    41.  
    42. if(fileInfo->fileName() =="." || fileInfo->fileName() =="..")
    43. ;
    44. else if(fileInfo->isDir())
    45. {
    46. QString destinationFilePath;
    47. destinationFilePath = destination + ("/") + fileInfo->fileName();
    48. dir1.mkdir(destinationFilePath,true);
    49. sourceFilePath = source + ("/") + fileInfo->fileName();
    50. CopyAllFilesandFolders(sourceFilePath,destinationFilePath);
    51. copy->setText(sourceFilePath);
    52.  
    53. }
    54.  
    55. else
    56. {
    57. QString destinationFilePath;
    58. destinationFilePath = destination+("/")+fileInfo->fileName();
    59. sourceFilePath = source+("/")+fileInfo->fileName();
    60. CopyFiles(sourceFilePath,destinationFilePath);
    61. copy->setText(sourceFilePath);
    62. }
    63.  
    64.  
    65. ReadNextDir();
    66. }
    67.  
    68.  
    69.  
    70. }
    71.  
    72.  
    73.  
    74. }
    75.  
    76.  
    77.  
    78. }
    79.  
    80.  
    81. bool Form1::CopyFiles(QString sourceFilePath,QString destinationFilePath)
    82. {
    83. bool success=false;
    84. QFile srcFile(sourceFilePath);
    85. QFile destFile(destinationFilePath);
    86. uint dataLength=4096;
    87. char*data = new char[dataLength];
    88. if(srcFile.open(IO_ReadOnly))
    89. {
    90. if(destFile.open(IO_WriteOnly))
    91. {
    92. while(!srcFile.atEnd())
    93. {
    94. memset(data,0*00,dataLength);
    95. int iTotalByteRead=srcFile.readBlock(data,dataLength);
    96. destFile.writeBlock(data,iTotalByteRead);
    97. }
    98. delete data;
    99. destFile.close();
    100. success=true;
    101. }
    102. srcFile.close();
    103. }
    104. return success;
    105. }
    106.  
    107. void Form1::SetSource()
    108. {
    109. m_StrSource = QFileDialog::getExistingDirectory(
    110. "/home",
    111. this,
    112. "get existing directory",
    113. "Choose a directory",
    114. TRUE );
    115.  
    116. source->setText(m_StrSource);
    117. }
    118.  
    119. void Form1::SetDestination()
    120. {
    121. m_StrDestination = QFileDialog::getExistingDirectory(
    122. "/home",
    123. this,
    124. "get existing directory",
    125. "Choose a directory",
    126. TRUE );
    127. destination->setText(m_StrDestination);
    128. }
    129.  
    130. void Form1::ReadNextDir()
    131. {
    132. QApplication * qApp;
    133. qApp->processEvents();
    134. progress->setProgress(++m_totalsteps);
    135.  
    136. }
    To copy to clipboard, switch view to plain text mode 


    Thanx in advance
    Last edited by jacek; 7th February 2007 at 13:33. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: DisplayTree Structure of the path

    Did you manage to solve the problem?

  3. #3
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: DisplayTree Structure of the path

    Hi Wysota

    Yes my this Problem is Solved

    Merry

Similar Threads

  1. Replies: 12
    Last Post: 7th February 2007, 13:30
  2. how to write a structure in a shared mem segment.
    By nass in forum General Programming
    Replies: 9
    Last Post: 26th September 2006, 13:11
  3. valid a path name
    By klaus1111 in forum Newbie
    Replies: 3
    Last Post: 23rd July 2006, 15:07
  4. Which path should I use?
    By Dark_Tower in forum Newbie
    Replies: 3
    Last Post: 8th April 2006, 12:09
  5. Replies: 1
    Last Post: 1st March 2006, 11:43

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.