Esempio n. 1
0
        public static void RemoveDeletedItems(string strDirectoryPath, SearchOption enuDeleteScope)
        {
            bool blnDirectoryExists = DirectoryManager.Exists(strDirectoryPath);

            if (blnDirectoryExists == true)
            {
                string strSearchPattern = "*" + FileManager.DeleteExtension;

                try
                {
                    string[] strDeletedDirectories = Directory.GetDirectories(strDirectoryPath, strSearchPattern, enuDeleteScope);
                    foreach (string strDeletedDirectory in strDeletedDirectories)
                    {
                        try
                        {
                            DirectoryManager.Delete(strDeletedDirectory, false);
                        }
                        catch
                        {
                            /// Ignore any errors since we are trying to remove files that
                            /// are marked for deletion.
                            ///
                        }
                    }
                }
                catch
                {
                    /// Ignore any errors since we are trying to remove files that
                    /// are marked for deletion.
                    ///
                }

                try
                {
                    string[] strDeletedFiles = Directory.GetFiles(strDirectoryPath, strSearchPattern, SearchOption.TopDirectoryOnly);
                    foreach (string strDeletedFile in strDeletedFiles)
                    {
                        try
                        {
                            FileManager.Delete(strDeletedFile, false);
                        }
                        catch
                        {
                            /// Ignore any errors since we are trying to remove files that
                            /// are marked for deletion.
                            ///
                        }
                    }
                }
                catch
                {
                    /// Ignore any errors since we are trying to remove files that
                    /// are marked for deletion.
                    ///
                }
            }
        }
Esempio n. 2
0
 public static void Delete(string strFilePath)
 {
     FileManager.Delete(strFilePath, true);
 }
Esempio n. 3
0
        public static void Move(string strFilePath, string strTargetDirectory, bool blnMoveOnlyIfNewer, bool blnBackupTarget)
        {
            bool blnFileExists = FileManager.Exists(strFilePath);

            if (blnFileExists == false)
            {
                throw new Exception("Source file '" + strFilePath + "' does not exist.");
            }
            FileInfo objFileToMove = 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, objFileToMove.Name);
            bool   blnTargetFileExists = FileManager.Exists(strTargetFilePath);

            if (blnTargetFileExists == true)
            {
                FileInfo objTargetFileInfo = new FileInfo(strTargetFilePath);
                if (objFileToMove.LastWriteTime.Ticks < objTargetFileInfo.LastWriteTime.Ticks)
                {
                    if (blnBackupTarget == true)
                    {
                        BackupFile(objFileToMove.FullName, strTargetDirectory);
                    }

                    if (blnMoveOnlyIfNewer == false)
                    {
                        FileManager.Delete(strTargetFilePath);
                        File.Move(objFileToMove.FullName, strTargetFilePath);
                    }
                    else
                    {
                        objFileToMove.Attributes = FileAttributes.Normal;
                        objFileToMove.Delete();
                    }
                }
                else
                {
                    if (blnBackupTarget == true)
                    {
                        BackupFile(strTargetFilePath, strTargetDirectory);
                    }

                    FileManager.Delete(strTargetFilePath);
                    File.Move(objFileToMove.FullName, strTargetFilePath);
                }
            }
            else
            {
                File.Move(objFileToMove.FullName, strTargetFilePath);
            }
        }