public void TestMoveTo() { var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file21.ext").ToString(); var tempDestLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file21-1.ext").ToString(); Assert.IsFalse(File.Exists(tempLongPathFilename)); File.Copy(longPathFilename, tempLongPathFilename); try { Assert.IsTrue(File.Exists(tempLongPathFilename)); var fi = new FileInfo(tempLongPathFilename); fi.MoveTo(tempDestLongPathFilename); try { Assert.IsFalse(File.Exists(tempLongPathFilename)); Assert.IsTrue(File.Exists(tempDestLongPathFilename)); } finally { File.Delete(tempDestLongPathFilename); } } finally { if (File.Exists(tempLongPathFilename)) { File.Delete(tempLongPathFilename); } } }
public override async Task <FileSystemResult> CopyAsync(IDirectory destination) { try { DirectoryImplementation to = destination as DirectoryImplementation; if (to == null) { return(new FileSystemResult("Destination should be a Local Directory")); } if (to is LocalRoot) { return(new FileSystemResult("Root cannot be destination")); } string destname = Path.Combine(to.FullName, Name); File.Copy(FullName, destname); FileInfo finfo = new FileInfo(destname); LocalFile local = new LocalFile(finfo, FS); local.Parent = destination; to.IntFiles.Add(local); return(await Task.FromResult(new FileSystemResult())); } catch (Exception e) { return(new FileSystemResult(e.Message)); } }
/// <summary> /// This method creates a temporary local copy of the file to read, /// because the MsgReader library doesn't support long paths, or /// streams that can be retrieved from the longpath library. /// Therefore longpath makes a copy of the file for us, and we /// work with the locally copied file. /// </summary> /// <returns></returns> private string GetTempLocalFile() { string tempPath = Path.GetTempPath() + Guid.NewGuid().ToString() + ".msg"; File.Copy(_FilePath, tempPath, true); return(tempPath); }
public static void CopyFile(string from, string to) { string directoryName = Path.GetDirectoryName(to); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } // FileUtil.CopyFileOrDirectory(from, to); try { File.Copy(from, to, true); } catch (Exception ex) { //Debug.LogError (string.Format ("{0}: {1}", ex.Message, ex.StackTrace)); } }
public void TestCopyWithoutOverwriteAndExistingFile() { var destLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("filename (Copy).ext").ToString(); File.Copy(longPathFilename, destLongPathFilename); try { Assert.IsTrue(File.Exists(destLongPathFilename)); Assert.Throws <IOException>(() => File.Copy(longPathFilename, destLongPathFilename)); } finally { File.Delete(destLongPathFilename); } }
public void TestCopyWithOverwrite() { var destLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("filename (Copy).ext").ToString(); File.Copy(longPathFilename, destLongPathFilename); try { Assert.IsTrue(File.Exists(destLongPathFilename)); File.Copy(longPathFilename, destLongPathFilename, true); Assert.AreEqual(File.ReadAllText(longPathFilename), File.ReadAllText(destLongPathFilename)); } finally { File.Delete(destLongPathFilename); } }
static void CopyFiles(string source, string dest, bool move, bool includeArchives = true) { if (move) { MarkFolderWritable(source); } MarkFolderWritable(dest); Console.WriteLine("{0} {1} => {2}", move ? "Moving" : "Copying", source, dest); source = source.TrimEnd('\\'); dest = dest.TrimEnd('\\'); if (!Directory.Exists(dest)) { Directory.CreateDirectory(dest); } Directory.EnumerateDirectories(source, "*", SearchOption.AllDirectories).Select(d => d.Replace(source, dest)).ForEach(path => Directory.CreateDirectory(path)); foreach (var file in Directory.EnumerateFiles(source, "*", SearchOption.AllDirectories).Where(f => Path.GetExtension(f) != ".nfo" && !Regex.IsMatch(Path.GetFileName(f), "All.Collection.Upload|WareZ-Audio", RegexOptions.IgnoreCase)).ToArray()) { if (Path.GetExtension(file) == ".sfv") { continue; } //if (!includeArchives && Regex.IsMatch(Path.GetExtension(file), @"\.(rar|r\d+|zip|iso)")) if (!includeArchives && Path.GetDirectoryName(file) == source && Regex.IsMatch(Path.GetExtension(file), @"\.(rar|r\d+|zip)")) { continue; } var newFile = file.Replace(source, dest); if (move) { if (File.Exists(newFile)) { File.Delete(newFile); } File.Move(file, newFile); } else { File.Copy(file, newFile, true); } } }
public IEnumerable <string> GetEmbeddedFiles() { MsgReader.Reader reader = new MsgReader.Reader(); string tempMsgFilePath = GetTempLocalFile(); DirectoryInfo tempDirectory = new DirectoryInfo(Path.GetTempPath()); DirectoryInfo tempOutputDirectory = tempDirectory.CreateSubdirectory(Guid.NewGuid().ToString()); reader.ExtractToFolder(tempMsgFilePath, tempOutputDirectory.FullName); List <string> tempFiles = new List <string>(); foreach (FileInfo file in tempOutputDirectory.EnumerateFiles()) { //HTM files will be the email itself, which is covered by reading contents //DB files are to exclude thumbs.db files if (file.Extension.ToUpper() != ".HTM" && file.Extension.ToUpper() != ".DB") { string thisTempFile = tempDirectory + Guid.NewGuid().ToString() + Path.GetExtension(file.Name); File.Copy(file.FullName, thisTempFile); tempFiles.Add(thisTempFile); } } try { File.Delete(tempMsgFilePath); tempOutputDirectory.Delete(true); } catch (Exception) { } return(tempFiles); }
public void DecryptCourse(List <ListViewItem> list) { if (string.IsNullOrWhiteSpace(txtCoursePath.Text)) { MessageBox.Show("Please select course path", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (string.IsNullOrWhiteSpace(txtDBPath.Text)) { MessageBox.Show("Please select database path", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (string.IsNullOrWhiteSpace(txtOutputPath.Text)) { MessageBox.Show("Please select output path", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } foreach (ListViewItem item in list) { CourseItem courseItem = listCourse.Where(r => r.Course.Name == item.Name).Select(r => r).FirstOrDefault(); if (chkDecrypt.Checked) { bgwDecrypt.ReportProgress(1, new Log { Text = $"Start to decrypt course \"{courseItem.Course.Title}\"", TextColor = Color.Magenta, NewLine = true, IsError = true }); //Create new course path with the output path var newCoursePath = Path.Combine(txtOutputPath.Text, this.CleanName(courseItem.Course.Title)); DirectoryInfo courseInfo = Directory.Exists(newCoursePath) ? new DirectoryInfo(newCoursePath) : Directory.CreateDirectory(newCoursePath); if (chkCopyImage.Checked && File.Exists($"{courseItem.CoursePath}\\image.jpg")) { File.Copy($"{courseItem.CoursePath}\\image.jpg", $"{newCoursePath}\\image.jpg", true); } //Get list all modules in current course List <Module> listModules = courseItem.Course.Modules; if (listModules.Count > 0) { // integer to add 1 if index should start at 1 int startAt1 = Convert.ToInt16(chkStartModuleIndexAt1.Checked); //Get each module foreach (Module module in listModules) { //Generate module hash name string moduleHash = this.ModuleHash(module.Name, module.AuthorHandle); //Generate module path string moduleHashPath = Path.Combine(courseItem.CoursePath, moduleHash); //Create new module path with decryption name string newModulePath = Path.Combine(courseInfo.FullName, $"{(startAt1 + module.Index):00}. {module.Title}"); if (Directory.Exists(moduleHashPath)) { DirectoryInfo moduleInfo = Directory.Exists(newModulePath) ? new DirectoryInfo(newModulePath) : Directory.CreateDirectory(newModulePath); //Decrypt all videos in current module folder this.DecryptAllVideos(moduleHashPath, module, moduleInfo.FullName); } else { bgwDecrypt.ReportProgress(1, new Log { Text = $"Folder {moduleHash} not found in the current course path", TextColor = Color.Red, NewLine = true, IsError = true }); } } } bgwDecrypt.ReportProgress(1, new Log { Text = $"Decrypt \"{courseItem.Course.Title}\" complete!", TextColor = Color.Magenta, NewLine = true, IsError = true }); } if (chkDelete.Checked) { try { Directory.Delete(courseItem.CoursePath, true); } catch (Exception ex) { bgwDecrypt.ReportProgress(1, new Log { Text = $"Delete folder course {courseItem.Course.Title} fail\n{ex.Message}", TextColor = Color.Gray, NewLine = true, IsError = true }); } try { RemoveCourseInDb(courseItem.CoursePath); } catch (Exception ex) { bgwDecrypt.ReportProgress(1, new Log { Text = $"Delete course {courseItem.Course.Title} from db fail\n{ex.Message}", TextColor = Color.Gray, NewLine = true, IsError = true }); } bgwDecrypt.ReportProgress(1, new Log { Text = $"Delete course {courseItem.Course.Title} success!", TextColor = Color.Magenta, NewLine = true }); } } bgwDecrypt.ReportProgress(100); }
public static void Copy(string sourcePath, string destinationPath, bool overwrite) { File.Copy(sourcePath, destinationPath, overwrite); }
public static void Copy(string sourcePath, string destinationPath) { File.Copy(sourcePath, destinationPath); }
public void Copy(string fromPath, string toPath) { File.Copy(fromPath, toPath); }