/// <summary> /// Renames the folder. /// </summary> /// <param name="name">The name.</param> /// <param name="collisionOption">The collision option.</param> /// <returns>Whether the folder was renamed (true) or not (false).</returns> public override bool Rename(string name, FolderCollisionOption collisionOption) { Exceptions.NotNullOrEmptyCheck(name, nameof(name)); string path = Path; switch (collisionOption) { case FolderCollisionOption.FailIfExists: if (Fenrir.FileSystem.FolderExists(System.IO.Path.Combine(path, name))) return false; break; case FolderCollisionOption.GenerateUniqueName: name = Fenrir.FileSystem.GenerateFolderUniqueName(path, name); break; case FolderCollisionOption.OpenIfExists: if (Fenrir.FileSystem.FolderExists(System.IO.Path.Combine(path, name))) return false; break; } string folder = System.IO.Path.Combine(path, name); System.IO.Directory.Move(FullPath, folder); Name = name; return true; }
/// <summary> /// Moves this folder to the specified destination. /// </summary> /// <param name="destinationPath">The destination path.</param> /// <param name="destinationName">Name of the destination.</param> /// <param name="collisionOption">The collision option.</param> /// <returns>Whether the folder was moved (true) or not (false).</returns> public override bool Move(AFolder destinationPath, string destinationName, FolderCollisionOption collisionOption) { Exceptions.NotNullCheck<AFolder>(destinationPath, nameof(destinationPath)); Exceptions.NotNullOrEmptyCheck(Name, nameof(destinationName)); string path = System.IO.Path.Combine(FullPath, destinationName); string endPath = System.IO.Path.Combine(destinationPath.FullPath, destinationName); if (Fenrir.FileSystem.FolderExists(path)) { switch (collisionOption) { case FolderCollisionOption.FailIfExists: if (Fenrir.FileSystem.FolderExists(endPath)) return false; break; case FolderCollisionOption.GenerateUniqueName: destinationName = Fenrir.FileSystem.GenerateFileUniqueName(destinationPath.FullPath, destinationName); endPath = System.IO.Path.Combine(destinationPath.FullPath, destinationName); break; case FolderCollisionOption.OpenIfExists: if (Fenrir.FileSystem.FolderExists(endPath)) return false; break; } System.IO.Directory.Move(path, endPath); return true; } return false; }
/// <summary> /// Copies a folder. /// </summary> /// <param name="folder">The folder.</param> /// <param name="destinationPath">The destination path.</param> /// <param name="destinationName">Name of the destination.</param> /// <param name="folderCollisionOption">The folder collision option.</param> /// <param name="fileCollisionOption">The file collision option.</param> /// <returns>An AFolder representing the file.</returns> public override AFolder CopyFolder(string folder, AFolder destinationPath, string destinationName, FolderCollisionOption folderCollisionOption, FileCollisionOption fileCollisionOption) { Exceptions.NotNullCheck<AFolder>(destinationPath, nameof(destinationPath)); Exceptions.NotNullOrEmptyCheck(Name, nameof(destinationName)); string path = System.IO.Path.Combine(FullPath, folder); if (Fenrir.FileSystem.FolderExists(path)) { AFolder newFolder = new FenrirFolder(path); return newFolder.Copy(destinationPath.FullPath, destinationName, folderCollisionOption, fileCollisionOption); } return null; }
/// <summary> /// Creates a folder in this System.IO.Directory. /// </summary> /// <param name="name">The name.</param> /// <param name="collisionOption">The collision option.</param> /// <returns>The new folder.</returns> public override AFolder CreateFolder(string name, FolderCollisionOption collisionOption) { Exceptions.NotNullOrEmptyCheck(name, nameof(name)); string path = FullPath; switch (collisionOption) { case FolderCollisionOption.FailIfExists: if (Fenrir.FileSystem.FolderExists(System.IO.Path.Combine(path, name))) return null; break; case FolderCollisionOption.GenerateUniqueName: name = Fenrir.FileSystem.GenerateFolderUniqueName(path, name); break; } string folder = System.IO.Path.Combine(path, name); System.IO.Directory.CreateDirectory(folder); return new FenrirFolder(folder); }
/// <summary> /// Copies the folder to the destination. /// </summary> /// <param name="destinationPath">The destination path.</param> /// <param name="destinationName">Name of the destination.</param> /// <param name="folderCollisionOption">The folder collision option.</param> /// <param name="fileCollisionOption">The file collision option.</param> /// <returns>An AFolder representing the new folder.</returns> public override AFolder Copy(AFolder destinationPath, string destinationName, FolderCollisionOption folderCollisionOption, FileCollisionOption fileCollisionOption) { Exceptions.NotNullCheck<AFolder>(destinationPath, nameof(destinationPath)); Exceptions.NotNullOrEmptyCheck(Name, nameof(destinationName)); string destination = destinationPath.FullPath; string path = System.IO.Path.Combine(destination, destinationName); switch (folderCollisionOption) { case FolderCollisionOption.FailIfExists: if (Fenrir.FileSystem.FolderExists(path)) return null; break; case FolderCollisionOption.GenerateUniqueName: destinationName = Fenrir.FileSystem.GenerateFileUniqueName(destination, destinationName); path = System.IO.Path.Combine(destination, destinationName); break; case FolderCollisionOption.OpenIfExists: if (Fenrir.FileSystem.FolderExists(path)) return new FenrirFolder(path); break; } System.IO.Directory.CreateDirectory(path); List<string> files = this.GetFileNames(); foreach (string str in files) CopyFile(str, destinationPath, str, fileCollisionOption); List<string> folders = this.GetFolderNames(); foreach (string str in folders) CopyFolder(str, destinationPath, str, folderCollisionOption, fileCollisionOption); return new FenrirFolder(path); }