/// <summary> /// Moves the directory. /// </summary> /// <exception cref="InvalidDataException">Directory was invalid.</exception> private static void MoveDirectory() { Console.WriteLine("Enter the new directory."); var tempDirectory = Console.ReadLine(); if (DirectoryManager.Test(tempDirectory)) { DirectoryManager.CoreDirectory(out string coreDirectory); DirectoryManager.Save(coreDirectory, tempDirectory); DefaultFiles.Create(tempDirectory); FileName.directory = tempDirectory; Console.WriteLine("Directory successfully moved to: " + tempDirectory); } else { throw new InvalidDataException("Directory is invalid"); } }
/// <summary> /// Tries to create a directory in the default location. /// </summary> /// <param name="coreDirectory">Location to store directory location.</param> /// <param name="directory">Location of directory.</param> /// <returns>True if successful, false otherwise.</returns> private static bool CreateDefaultDirectory(string coreDirectory, out string directory) { try { directory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); } catch (PlatformNotSupportedException) { directory = ""; Console.WriteLine("Platform not supported for accessing MyDocuments."); SuggestManualCreation(coreDirectory); return(false); } directory += programFolder; try { Directory.CreateDirectory(directory); } catch (ArgumentException) { Console.WriteLine("Invalid directory exception."); SuggestManualCreation(coreDirectory); return(false); } catch (Exception e) when(e is IOException || e is UnauthorizedAccessException || e is NotSupportedException) { Console.WriteLine("Failed to create directory at: \"" + directory + "\"."); SuggestManualCreation(coreDirectory); return(false); } if (Test(directory)) { DefaultFiles.Create(directory); Save(coreDirectory, directory); Console.WriteLine("Directory created at: \"" + directory + "\"."); return(true); } Console.WriteLine("Directory created at: \"" + directory + "\", but program failed to access it."); SuggestManualCreation(coreDirectory); return(false); }