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 bool ItemExists(string path) { PinvokeFilesystem.GetFileAttributesExFromApp((@"\\?\" + path), PinvokeFilesystem.GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, out var lpFileInfo); if (lpFileInfo.dwFileAttributes != 0) { return(true); } else { return(false); } }
public async Task DeleteAsync(string path) { path = GetLocalVfsPath(path); PinvokeFilesystem.GetFileAttributesExFromApp((@"\\?\" + path), PinvokeFilesystem.GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, out var lpFileInfo); //this handling is only neccessary as winscp for some reason sends directory delete commands as file delete commands if (lpFileInfo.dwFileAttributes.HasFlag(System.IO.FileAttributes.Directory)) { await RecursivelyDeleteDirectoryAsync(path); } else if (lpFileInfo.dwFileAttributes != 0) { await Task.Run(() => { PinvokeFilesystem.DeleteFileFromApp(@"\\?\" + path); }); } else { throw new FileBusyException("Items of unknown type can't be deleted"); } MainPage.Current.RefreshStorage(); }