/// <summary> /// Parse the given file path string and extract the directory path and file name. /// </summary> /// <param name="filePath"> /// The file path string to be parsed /// </param> protected void ParseFilePath(string filePath) { // Obtain the absolute file path. Throw an exception if the path is invalid. string absoluteFilePath = FileOps.GetAbsoluteFilePath(filePath); // Parse the file path and extract the directory path DirectoryPath = FileOps.GetDirectoryPath(absoluteFilePath); // Throw an exception if the directory path is null if (DirectoryPath == NULL) { throw new FilePathException("Directory path can't be null") { FileName = FileName, FilePath = NULL }; } // Parse the file path and extract the file name FileName = FileOps.GetFileName(absoluteFilePath); // Throw an exception if the file name is null if (FileName == NULL) { throw new FilePathException("File name can't be null") { FilePath = DirectoryPath, FileName = FileName }; } }
/// <summary> /// Move the file to a different directory /// </summary> /// <param name="directoryPath"> /// The target directory path /// </param> /// <returns> /// Returns the full file path of the target file /// </returns> public virtual string Move(string directoryPath) { // First copy the current file to the target directory string filePath = Copy(directoryPath); string targetPath = FileOps.GetDirectoryPath(filePath); // Delete the file from the source location if the copy operation was successful try { File.Delete(FilePath); } catch (Exception e) { throw new FileOperationException("Error removing file from source location", e) { SourcePath = FilePath, TargetPath = targetPath }; } DirectoryPath = targetPath; return(filePath); }