public static void Copy(string strFilePath, string strTargetDirectory, bool blnCopyOnlyIfNewer, bool blnBackupTarget) { bool blnFileExists = FileManager.Exists(strFilePath); if (blnFileExists == false) { throw new Exception("Source file '" + strFilePath + "' does not exist."); } FileInfo objFileToCopy = new FileInfo(strFilePath); bool blnTargetDirectoryExists = DirectoryManager.Exists(strTargetDirectory); if (blnTargetDirectoryExists == false) { try { DirectoryManager.Create(strTargetDirectory); } catch (Exception objException) { throw new Exception("Target directory '" + strTargetDirectory + "' could not be created.", objException); } } DirectoryInfo objTargetDirectory = new DirectoryInfo(strTargetDirectory); string strTargetFilePath = Path.Combine(strTargetDirectory, objFileToCopy.Name); bool blnTargetFileExists = FileManager.Exists(strTargetFilePath); if (blnTargetFileExists == true) { FileInfo objTargetFileInfo = new FileInfo(strTargetFilePath); if (objFileToCopy.LastWriteTime.Ticks < objTargetFileInfo.LastWriteTime.Ticks) { if (blnBackupTarget == true) { BackupFile(objFileToCopy.FullName, strTargetDirectory); } if (blnCopyOnlyIfNewer == false) { objTargetFileInfo.Attributes = FileAttributes.Normal; objTargetFileInfo.Delete(); File.Copy(objFileToCopy.FullName, strTargetFilePath); } } else { if (blnBackupTarget == true) { BackupFile(strTargetFilePath, strTargetDirectory); } objTargetFileInfo.Attributes = FileAttributes.Normal; objTargetFileInfo.Delete(); File.Copy(objFileToCopy.FullName, strTargetFilePath); } } else { File.Copy(objFileToCopy.FullName, strTargetFilePath); } }
public static void Delete(string strFilePath) { FileManager.Delete(strFilePath, true); }
public static FileAttributes GetAttributes(string strFilePath) { return(FileManager.GetAttributes(strFilePath, FileAttributes.Normal)); }