public async Task RenameAsync(string fromPath, string toPath) { //get full path from parameter "fromPath" fromPath = GetLocalVfsPath(fromPath); toPath = GetLocalVfsPath(toPath); PinvokeFilesystem.GetFileAttributesExFromApp((@"\\?\" + fromPath), PinvokeFilesystem.GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, out var lpFileInfo); if (lpFileInfo.dwFileAttributes == 0) { throw new FileNoAccessException("Can't find the item to rename"); } else { if (lpFileInfo.dwFileAttributes.HasFlag(System.IO.FileAttributes.Directory)) { PinvokeFilesystem.CreateDirectoryFromApp(@"\\?\" + toPath, IntPtr.Zero); if (!(await MoveFolderAsync(fromPath, toPath))) { throw new FileBusyException("Some items can't be moved"); } } else { await Task.Run(() => { PinvokeFilesystem.CopyFileFromApp(fromPath, toPath, false); PinvokeFilesystem.DeleteFileFromApp(fromPath); }); } } }
public async Task RecursivelyCreateDirectoryAsync(string path) { string parentPath = System.IO.Directory.GetParent(path).ToString(); var itemexists = ItemExists(parentPath); if (!itemexists) { await RecursivelyCreateDirectoryAsync(parentPath); } await Task.Run(() => { PinvokeFilesystem.CreateDirectoryFromApp((@"\\?\" + path), IntPtr.Zero); }); }
private async Task <bool> MoveFolderAsync(string folder, string destination, bool firstcall = true) { List <MonitoredFolderItem> mininfo = PinvokeFilesystem.GetMinInfo(folder); foreach (MonitoredFolderItem item in mininfo) { string itempath = System.IO.Path.Combine(item.ParentFolderPath, item.Name); string targetpath = System.IO.Path.Combine(destination, item.Name); if (item.attributes.HasFlag(System.IO.FileAttributes.Directory)) { await Task.Run(() => { PinvokeFilesystem.CreateDirectoryFromApp(@"\\?\" + targetpath, IntPtr.Zero); }); await MoveFolderAsync(itempath, targetpath, false); } else { //move file await Task.Run(() => { PinvokeFilesystem.CopyFileFromApp(@"\\?\" + itempath, @"\\?\" + targetpath, false); PinvokeFilesystem.DeleteFileFromApp(@"\\?\" + itempath); }); } } mininfo = PinvokeFilesystem.GetMinInfo(folder); if (mininfo.Count() == 0) { await Task.Run(() => { PinvokeFilesystem.RemoveDirectoryFromApp(@"\\?\" + folder); }); if (firstcall) { MainPage.Current.RefreshStorage(); } return(true); } else { return(false); } }