static public void CopyFolder(string sourceFolder, string destFolder) { if (isDirectory(sourceFolder)) { if (!Directory.Exists(destFolder)) { Directory.CreateDirectory(destFolder); } string[] files = Directory.GetFiles(sourceFolder); foreach (string file in files) { string name = Path.GetFileName(file); string dest = Path.Combine(destFolder, name); dest = FileInfoExtension.getFilepathCheckExist(name); File.Copy(file, dest); } string[] folders = Directory.GetDirectories(sourceFolder); foreach (string folder in folders) { string name = Path.GetFileName(folder); string dest = Path.Combine(destFolder, name); CopyFolder(folder, dest); } } }
private Error runFileMode(BackgroundWorker worker, string name) { var isSourceDelete = Convert.ToBoolean(AppConfiguration.GetAppConfig("SourceDelete")); var nameOnGoogleDrive = AppConfiguration.GetAppConfig("NameOnGoogleDrive"); var destPath = AppConfiguration.GetAppConfig("LocalPath"); var credentialPath = AppConfiguration.GetAppConfig("CredentialPath"); var target = destPath + "\\" + Path.GetFileName(name); Program.AddLog("Start copy to " + target); //Create a tast to run copy file target = FileInfoExtension.getFilepathCheckExist(target); File.Copy(name, target); worker.ReportProgress(30, "Start security " + name); /// 인터넷 체크 Program.AddLog("Internet connection check.. "); if (!GoogleDriveApi.CheckForInternetConnection()) { Program.AddLog("Failed."); return(Error.FAILED_INTERNET_CONNECTION); } /// root id 가져오기 var id = GoogleDriveApi.getBackupFolderId(nameOnGoogleDrive); if (String.IsNullOrEmpty(id)) { id = GoogleDriveApi.CreateFolder(nameOnGoogleDrive); } Program.AddLog("Start google drive upload.. " + id); //Google upload worker.ReportProgress(80, "Start security " + target); Program.AddLog("Compression success.. "); if (GoogleDriveApi.FileUploadInFolder(id, target)) { Program.AddLog("Upload success."); if (isSourceDelete) { FileInfoExtension.DeleteFolder(name); } } else { return(Error.FAILED_UPLOAD); } return(Error.SUCCESS); }