
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.
.
#include <dirent.h>
#include <sys/stat.h>
DIR
* d
= opendir
(QFile::encodeName(dir
));
dirent *ent;
if(d == NULL)//Non-readble
return;
//code for copying dir goes here ---------------------------- 1 ------------------------------
.
.
while((ent = readdir(d))){
if( entry == "." || entry == ".." )
continue;
entry.
prepend( QFile::encodeName( dir.
endsWith( "/" ) ? dir
: dir
+ "/" ) );
if(stat(entry, &statBuf) == 0){
if(S_ISREG(statBuf.st_mode)){
//code for copying file goes here
}
if(S_ISDIR(statBuf.st_mode)){
//code for copying dir goes here ---------- same as 1-----------------------
.
.
copy(dir_name_with_path);
}
}
}
closedir( d );
}
.
#include <dirent.h>
#include <sys/stat.h>
void copy(QString dir){
DIR * d = opendir(QFile::encodeName(dir));
dirent *ent;
if(d == NULL)//Non-readble
return;
//code for copying dir goes here ---------------------------- 1 ------------------------------
.
.
while((ent = readdir(d))){
QByteArray entry = ent->d_name;
if( entry == "." || entry == ".." )
continue;
entry.prepend( QFile::encodeName( dir.endsWith( "/" ) ? dir : dir + "/" ) );
if(stat(entry, &statBuf) == 0){
if(S_ISREG(statBuf.st_mode)){
QString file_name_with_path = QString::fromLocal8Bit(entry);
//code for copying file goes here
}
if(S_ISDIR(statBuf.st_mode)){
QString dir_name_with_path = QString::fromLocal8Bit(entry);
//code for copying dir goes here ---------- same as 1-----------------------
.
.
copy(dir_name_with_path);
}
}
}
closedir( d );
}
To copy to clipboard, switch view to plain text mode
Bookmarks