Quote Originally Posted by monaem
but this directory contains other directories,how can i do?
I have given below a trimmed down version which I used in an app. You still need to do some work.
Qt Code:
  1. .
  2. #include <dirent.h>
  3. #include <sys/stat.h>
  4.  
  5. void copy(QString dir){
  6. DIR * d = opendir(QFile::encodeName(dir));
  7. dirent *ent;
  8. if(d == NULL)//Non-readble
  9. return;
  10. //code for copying dir goes here ---------------------------- 1 ------------------------------
  11. .
  12. .
  13. while((ent = readdir(d))){
  14. QByteArray entry = ent->d_name;
  15. if( entry == "." || entry == ".." )
  16. continue;
  17. entry.prepend( QFile::encodeName( dir.endsWith( "/" ) ? dir : dir + "/" ) );
  18. if(stat(entry, &statBuf) == 0){
  19. if(S_ISREG(statBuf.st_mode)){
  20. QString file_name_with_path = QString::fromLocal8Bit(entry);
  21. //code for copying file goes here
  22. }
  23. if(S_ISDIR(statBuf.st_mode)){
  24. QString dir_name_with_path = QString::fromLocal8Bit(entry);
  25. //code for copying dir goes here ---------- same as 1-----------------------
  26. .
  27. .
  28. copy(dir_name_with_path);
  29. }
  30. }
  31. }
  32. closedir( d );
  33. }
To copy to clipboard, switch view to plain text mode