2011-05-03 92 views
0

我在文件浏览器上工作,并且我还有一个允许复制文件夹和文件的功能。我面临的问题是,我的功能似乎适用于单个文件夹复制操作和多文件操作。但是,当我尝试复制文件夹与里面的子文件夹foder似乎并没有复制多个文件夹。复制功能问题

我在这里做错了什么?请提出建议。下面是我HV代码编写

void Browser::copy() 
{ 
    MarkClicked=false; 

    if(multiSelect == true) 
    { 
     for(int i=0;i<indexList.size();i++) 
     { 

      qDebug()<<"indexlist.at(i)= "<<indexList.at(i); 
      source_files.append(model->filePath(indexList.at(i))); 

     } 
    } 
    else 
    { 
     index=list->selectionModel()->currentIndex(); 
     source_file = (model->filePath(index)); 
    } 
    CopyClicked=true; 
    copyAct->setEnabled(false); 
    CopyMenuRemoved=true; 
    pasteAct->setEnabled(true); 
    PasteMenuRmoved=false; 

} 


/* 
    This will perform paste operation. 
*/ 
void Browser::pasteFile() 
{ 

    CopyClicked=false; 

    dest_index=list->selectionModel()->currentIndex(); 
    QString destinationDir= model->filePath(dest_index); 

    if(multiSelect == true) 
    { 

     progress = new QProgressDialog("Copying...","",0, indexList.size(),this,Qt::SplashScreen); 
     progress->setAttribute(Qt::WA_DeleteOnClose); 
     progress->setWindowModality(Qt::WindowModal); 

     for(int i=0;i<indexList.size();i++) 
     { 
      progress->setValue(i); 
      progress->show(); 

      if(model->isDir(indexList.at(i))) 
      { 
       QDir srcdir(source_files.at(i)); 
       destinationDir = model->filePath(dest_index)+"/"+srcdir.dirName(); 
      } 
      else 
      { 
       destinationDir = model->filePath(dest_index); 
      } 
       fileInfo=QFileInfo(source_files.at(i)); 
       copySingle(source_files.at(i),destinationDir); 
     } 
     progress->close(); 
     unmarkAll(); 
    } 
    else 
    { 
     progress = new QProgressDialog("Copying...","",0, 0,this,Qt::SplashScreen); 
     progress->setAttribute(Qt::WA_DeleteOnClose); 
     progress->setWindowModality(Qt::WindowModal); 
     progress->show(); 
     if(model->isDir(index)) 
     { 
      QDir srcdir(source_file); 
      destinationDir = model->filePath(dest_index)+"/"+srcdir.dirName(); 
      qDebug()<<"destination dir ===="<<destinationDir; 
     }else 
     { 
      destinationDir = model->filePath(dest_index); 
      qDebug()<<"destination dir ===="<<destinationDir; 
     } 
     fileInfo=QFileInfo(source_file); 
     copySingle(source_file,destinationDir); 
     unmarkAll(); 
    } 
     progress->close(); 
     unmarkAll(); 


    copyAct->setEnabled(true); 
    CopyMenuRemoved=false; 
    pasteAct->setEnabled(false); 
    PasteMenuRmoved=true; 

} 


void Browser::copySingle(QString source_file,QString destinationDir) 
{ 
    if(model->fileInfo(index).isDir()) 
    { 
      sourceDir=QDir(source_file); 
      if(!sourceDir.exists()) 
       return; 
      QDir destDir(destinationDir); 
      if(!destDir.exists()) 
      { 
       destDir.mkdir(destinationDir); 
      } 
      QStringList files = sourceDir.entryList(QDir::Files); 
      for(int i = 0; i< files.count(); i++) 
      { 
       QString srcName = source_file + "/" + files[i]; 
       QString destName = destinationDir + "/" + files[i]; 
       QFile::copy(srcName, destName); 
      } 
      files.clear(); 
      files = sourceDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); 
      for(int i = 0; i< files.count(); i++) 
      { 
       QString srcName = source_file + "/" + files[i]; 
       QString destName = destinationDir + "/" + files[i]; 
       copySingle(srcName, destName); 
      } 
    } 
    else 
    { 
      QString destinationFile = destinationDir + "/" + fileInfo.fileName(); 
      QFile::copy(source_file, destinationFile); 

    } 
    progress->close(); 
} 
+0

没有人能提供任何建议吗? – prakashpun 2011-05-06 03:44:29

+0

伙计们..我需要一些帮助在这里... – prakashpun 2011-05-19 06:45:19

回答