private void MoveDirectory(string srcPath, string dstPath, FileMoveInfo move) { if (!Directory.Exists(srcPath)) { throw new IOException("Can't find source directory".Localize()); } if (!Directory.Exists(dstPath)) { Directory.CreateDirectory(dstPath); m_fileOperations.Add(new DirectoryMoveOperation(srcPath, dstPath)); } foreach (string filePath in Directory.GetFiles(srcPath)) { string fileName = filePath.Substring(srcPath.Length + 1); MoveFile(filePath, Path.Combine(dstPath, fileName), move); } foreach (string directoryPath in Directory.GetDirectories(srcPath)) { string childName = directoryPath.Substring(srcPath.Length + 1); MoveDirectory(directoryPath, Path.Combine(dstPath, childName), move); } if (move.Type == FileMoveType.Delete || move.Type == FileMoveType.Move) { Directory.Delete(srcPath); } }
private void MoveDirectory(string srcPath, string dstPath, FileMoveInfo move) { if (!Directory.Exists(srcPath)) throw new IOException("Can't find source directory".Localize()); if (!Directory.Exists(dstPath)) { Directory.CreateDirectory(dstPath); m_fileOperations.Add(new DirectoryMoveOperation(srcPath, dstPath)); } foreach (string filePath in Directory.GetFiles(srcPath)) { string fileName = filePath.Substring(srcPath.Length + 1); MoveFile(filePath, Path.Combine(dstPath, fileName), move); } foreach (string directoryPath in Directory.GetDirectories(srcPath)) { string childName = directoryPath.Substring(srcPath.Length + 1); MoveDirectory(directoryPath, Path.Combine(dstPath, childName), move); } if (move.Type == FileMoveType.Delete || move.Type == FileMoveType.Move) { Directory.Delete(srcPath); } }
private void MoveFile(string srcPath, string dstPath, FileMoveInfo move) { if (!File.Exists(srcPath)) { throw new IOException("Can't find source file".Localize()); } if (File.Exists(dstPath)) { if (move.Type == FileMoveType.Delete) { // deleting, get rid of any file in temp directory File.SetAttributes(dstPath, FileAttributes.Normal); File.Delete(dstPath); } else if (!move.AllowOverwrites) { throw new IOException("Can't overwrite existing file".Localize()); } } switch (move.Type) { case FileMoveType.Move: File.Move(srcPath, dstPath); break; case FileMoveType.Copy: File.Copy(srcPath, dstPath, move.AllowOverwrites); break; case FileMoveType.Delete: File.Move(srcPath, dstPath); break; default: throw new InvalidOperationException("illegal FileMoveType value"); } m_fileOperations.Add(new FileMoveOperation(srcPath, dstPath)); }
private void MoveFile(string srcPath, string dstPath, FileMoveInfo move) { if (!File.Exists(srcPath)) throw new IOException("Can't find source file".Localize()); if (File.Exists(dstPath)) { if (move.Type == FileMoveType.Delete) { // deleting, get rid of any file in temp directory File.SetAttributes(dstPath, FileAttributes.Normal); File.Delete(dstPath); } else if (!move.AllowOverwrites) { throw new IOException("Can't overwrite existing file".Localize()); } } switch (move.Type) { case FileMoveType.Move: File.Move(srcPath, dstPath); break; case FileMoveType.Copy: File.Copy(srcPath, dstPath, move.AllowOverwrites); break; case FileMoveType.Delete: File.Move(srcPath, dstPath); break; default: throw new InvalidOperationException("illegal FileMoveType value"); } m_fileOperations.Add(new FileMoveOperation(srcPath, dstPath)); }