def transferFile(self, src_path): dest_path = self.model.filePath(self.rootIndex()) src_file = QFile() src_file.setFileName(src_path) src_file_info = QFileInfo(src_path) dst_path = os.path.join(dest_path, src_file_info.fileName()) src_file.copy(dst_path)
def copyRecursively(self, src, tgt): src_info = QFileInfo(src) if src_info.isDir(): tgt_dir = QDir(tgt) if not tgt_dir.mkdir(src_info.fileName()): return False src_dir = QDir(src) fnames = src_dir.entryList(QDir.Files | QDir.Dirs | QDir.NoDotAndDotDot | QDir.Hidden | QDir.System) for fname in fnames: new_src = os.path.join(src, fname) new_tgt = os.path.join(tgt, src_info.fileName()) if not self.copyRecursively(new_src, new_tgt): return False elif src_info.isFile(): fname = src_info.fileName() if not QFile.copy(src, os.path.join(tgt, fname)): return False return True