/// <summary> /// Moves item in local storage. Creates <paramref name="destinationFolder"/> if not exists. /// </summary> /// <param name="item"> The item to move. </param> /// <param name="destinationFolder"> The destination folder. </param> /// <param name="name"> New item name. </param> /// <exception cref="ArgumentNullException"> /// Throw when <paramref name="item"/> is null or <paramref name="destinationFolder"/> is null or if <paramref name="name"/> is null or empty. /// </exception> /// <exception cref="PathTooLongException"> /// The specified path, file name, or both exceed the system-defined maximum length. /// </exception> /// <exception cref="UnauthorizedAccessException"> /// The caller does not have the required permission. /// </exception> /// <exception cref="IOException"> /// The destination item already exists or <paramref name="item"/> not found or destination item already exists. /// </exception> public void Move(LocalItem item, LocalFolder destinationFolder, string name) { if (item == null) { throw new ArgumentNullException(nameof(item)); } if (destinationFolder == null) { throw new ArgumentNullException(nameof(destinationFolder)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } if (!destinationFolder.IsExists) { Directory.CreateDirectory(destinationFolder.Path); } string newPath = Path.Combine(destinationFolder.Path, name); if (item is LocalFile) { File.Move(item.Path, newPath); } else { Directory.Move(item.Path, newPath); } }
/// <summary>Gets folder content as <see cref="LocalItem"/> collection.</summary> /// <param name="localFolder">The local folder.</param> /// <returns>The <see cref="LocalItem"/> array.</returns> public LocalItem[] GetFolderContentOrEmpty(LocalFolder localFolder) { if (!localFolder.IsExists) { return(new LocalItem[0]); } return(this.GetFolderContent(localFolder)); }
/// <summary>Gets folder content as <see cref="LocalItem"/> collection.</summary> /// <param name="folder">The folder.</param> /// <returns>The <see cref="LocalItem"/> array.</returns> /// <exception cref="NSErrorException"> if directory enumeration failed. </exception> public LocalItem[] GetFolderContent(LocalFolder folder) { if (!folder.IsExists) { return(new LocalItem[0]); } NSError error; NSUrl[] files = NSFileManager.DefaultManager.GetDirectoryContent( NSUrl.FromFilename(folder.Path), null, NSDirectoryEnumerationOptions.SkipsHiddenFiles, out error); error.ThrowNotNullAsException(); return(files.Select(f => this.GetItem(f.Path)).ToArray()); }