Beispiel #1
0
        public static void Create(String path, NameConflictOption aNameConflictOption)
        {
            if (File.Exists(path))
            {
                switch (aNameConflictOption)
                {
                case NameConflictOption.Cancel:
                case NameConflictOption.Skip:
                    return;

                case NameConflictOption.Overwrite:
                    FileExt.Delete(path);
                    break;

                case NameConflictOption.RenameExisting:
                    FileExt.Move(path, FileExt.MakeUnique(path));
                    break;

                case NameConflictOption.RenameNew:
                    throw new InvalidDataException("Can't rename a file we are trying to create");

                default:
                    break;
                }
            }
            DirectoryExt.Create(Path.GetDirectoryName(path));
            FileStream stream = File.Create(path);

            stream.Close();
        }
Beispiel #2
0
        /// <summary>
        /// Delete all files in the given directory that match the provided pattern.
        /// </summary>
        /// <param name="aPath">The directory where the files should be found.</param>
        /// <param name="aSearchOption">The directory search options.</param>
        /// <returns>If the deletion was successful.</returns>
        public static bool DeleteFiles(String aPath, DirectorySearchOption aSearchOption)
        {
            bool success = true;

            if (Directory.Exists(aPath))
            {
                success = FileExt.Delete(DirectoryExt.GetFiles(aPath, aSearchOption));
            }
            return(success);
        }