public IResult <Result.InternalTypes.Void> RenameDirectory(string basePath, string oldName, string newName) { var oldPathResult = _pathManager.Combine(basePath, oldName); if (!oldPathResult.IsSuccess) { return(new FailureResult(oldPathResult.Exception)); } var newPathResult = _pathManager.Combine(basePath, newName); if (!newPathResult.IsSuccess) { return(new FailureResult(newPathResult.Exception)); } try { ValidateNameLength(newPathResult.Data); Directory.Move(oldPathResult.Data, newPathResult.Data); return(new SuccessResult()); } catch (Exception e) { return(new FailureResult(e)); } }
//static void Unmount() //{ // Console.WriteLine("Unmounting G:"); // StartProcess(@"C:\Program Files\PowerISO\piso.exe", "unmount G:"); //} public static void CategorizeLibraryFolders() { var folders = Directory.EnumerateDirectories(Paths.OutputPath, "*", SearchOption.TopDirectoryOnly); foreach (var folder in folders) { if (Path.GetFileName(folder) == "_Kontakt" || Path.GetFileName(folder) == "_Loops") { continue; } var files = Directory.EnumerateFiles(folder, "*.nki", SearchOption.AllDirectories).ToArray(); if (files.Length > 0) { Directory.Move(folder, Paths.OutputPath + @"\_Kontakt\" + Path.GetFileName(folder)); } else { files = Directory.EnumerateFiles(folder, "*.iso", SearchOption.AllDirectories).ToArray(); files = files.Concat(Directory.EnumerateFiles(folder, "*.bin", SearchOption.AllDirectories)).ToArray(); if (files.Length > 0) { Directory.Move(folder, Paths.OutputPath + @"\_Iso\" + Path.GetFileName(folder)); } else { Directory.Move(folder, Paths.OutputPath + @"\_Loops\" + Path.GetFileName(folder)); } } } }
public void TestInUseMove() { const bool recursive = true; #if SHORT_SOURCE var tempPathFilename1 = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), System.IO.Path.GetRandomFileName()); System.IO.Directory.CreateDirectory(tempPathFilename1); Assert.IsTrue(System.IO.Directory.Exists(Path.GetFullPath(tempPathFilename1))); var tempPathFilename2 = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), System.IO.Path.GetRandomFileName()); System.IO.Directory.CreateDirectory(tempPathFilename2); Assert.IsTrue(System.IO.Directory.Exists(System.IO.Path.GetFullPath(tempPathFilename2))); try { using ( var writer = System.IO.File.CreateText(System.IO.Path.Combine(tempPathFilename2, "TestInUseMove"))) { string destinationPath = System.IO.Path.GetFullPath(System.IO.Path.Combine(tempPathFilename1, System.IO.Path.GetFileName(tempPathFilename2))); System.IO.Directory.Move(tempPathFilename2, destinationPath); Assert.IsTrue(System.IO.Directory.Exists(System.IO.Path.GetFullPath(tempPathFilename1))); Assert.IsFalse(System.IO.Directory.Exists(System.IO.Path.GetFullPath(tempPathFilename2))); Assert.IsTrue(System.IO.Directory.Exists(destinationPath)); } } catch (Exception e) { throw; } finally { Directory.Delete(tempPathFilename1, recursive); Directory.Delete(tempPathFilename2, recursive); } #endif var tempLongPathFilename1 = Path.Combine(uncDirectory, Path.GetRandomFileName()); Directory.CreateDirectory(tempLongPathFilename1); Assert.IsTrue(Directory.Exists(Path.GetFullPath(tempLongPathFilename1))); var tempLongPathFilename2 = Path.Combine(uncDirectory, Path.GetRandomFileName()); Directory.CreateDirectory(tempLongPathFilename2); Assert.IsTrue(Directory.Exists(Path.GetFullPath(tempLongPathFilename2))); try { using ( var writer = File.CreateText(Path.Combine(tempLongPathFilename2, "TestInUseMove"))) { string destinationPath = Path.GetFullPath(Path.Combine(tempLongPathFilename1, Path.GetFileName(tempLongPathFilename2))); Directory.Move(tempLongPathFilename2, destinationPath); Assert.IsTrue(Directory.Exists(Path.GetFullPath(tempLongPathFilename1))); Assert.IsFalse(Directory.Exists(Path.GetFullPath(tempLongPathFilename2))); Assert.IsTrue(Directory.Exists(destinationPath)); } } finally { Directory.Delete(tempLongPathFilename1, recursive); Directory.Delete(tempLongPathFilename2, recursive); } }
public override async Task <FileSystemResult> RenameAsync(string newname) { if (string.Equals(Name, newname)) { return(new FileSystemResult("Unable to rename, names are the same")); } string parentPath = Path.GetDirectoryName(FullName); string newfullname = Path.Combine(parentPath, newname); Directory.Move(FullName, newfullname); DirectoryInfo dinfo = new DirectoryInfo(newfullname); _directory = dinfo; return(await Task.FromResult(new FileSystemResult())); }
public override async Task <FileSystemResult> RenameAsync(string newname) { if (string.Equals(Name, newname)) { return(new FileSystemResult("Unable to rename, names are the same")); } string oldFullname = this.FullName; string newfullname = Path.Combine(Parent.FullName, newname); Directory.Move(FullName, newfullname); FS.Refs.Remove(oldFullname); DirectoryInfo dinfo = new DirectoryInfo(newfullname); _directory = dinfo; FS.Refs[FullName] = this; return(await Task.FromResult(new FileSystemResult())); }
public override async Task <FileSystemResult> MoveAsync(IDirectory destination) { DirectoryImplementation to = destination as DirectoryImplementation; if (to == null) { return(new FileSystemResult("Destination should be a Local Directory")); } if (to is LocalRoot) { return(new FileSystemResult("Root cannot be destination")); } string destname = Path.Combine(to.FullName, Name); Directory.Move(FullName, destname); Parent = destination; return(await Task.FromResult(new FileSystemResult())); }
public static void InstallLibs() { // Unmount(); var files = Directory.EnumerateFiles(Paths.ToProcessPath, "*").ToArray(); var archives = GetArchiveFiles(files); foreach (var archive in archives) { CleanupTempFolders(); try { Console.Write("Processing {0}\r\n", archive); ProcessArchive(Paths.ToProcessPath, Paths.ToProcessPath, archive, files, Paths.OutputPath); var associatedArchives = GetAssociatedArchives(archive, files); foreach (var file in associatedArchives) { Directory.Move(file, file.Replace(Paths.ToProcessPath, Paths.ProcessedPath)); } Console.WriteLine("Successfully processed {0}", archive); } catch (Exception e) { foreach (var key in e.Data.Keys) { Console.WriteLine(e.Data[key] + ": " + key); } Console.Write(e.Message); Console.WriteLine("Errors while processing {0}", archive); foreach (var file in GetAssociatedArchives(archive, files)) { Directory.Move(file, Paths.ToProcessPath + @"\_Broken\" + Path.GetFileName(file)); } } finally { Console.WriteLine(); CleanupTempFolders(); } } }
public void TestMove() { var tempLongPathFilename1 = Path.Combine(uncDirectory, Path.GetRandomFileName()); Directory.CreateDirectory(tempLongPathFilename1); Assert.IsTrue(Directory.Exists(Path.GetFullPath(tempLongPathFilename1))); var tempLongPathFilename2 = Path.Combine(uncDirectory, Path.GetRandomFileName()); Directory.CreateDirectory(tempLongPathFilename2); Assert.IsTrue(Directory.Exists(Path.GetFullPath(tempLongPathFilename2))); string destinationPath = Path.GetFullPath(Path.Combine(tempLongPathFilename1, Path.GetFileName(tempLongPathFilename2))); Directory.Move(tempLongPathFilename2, destinationPath); Assert.IsTrue(Directory.Exists(Path.GetFullPath(tempLongPathFilename1))); Assert.IsFalse(Directory.Exists(Path.GetFullPath(tempLongPathFilename2))); Assert.IsTrue(Directory.Exists(destinationPath)); const bool recursive = true; Directory.Delete(tempLongPathFilename1, recursive); Directory.Delete(tempLongPathFilename2, recursive); }
public override async Task <FileSystemResult> MoveAsync(IDirectory destination) { DirectoryImplementation to = destination as DirectoryImplementation; if (to == null) { return(new FileSystemResult("Destination should be a Local Directory")); } if (to is LocalRoot) { return(new FileSystemResult("Root cannot be destination")); } string destname = Path.Combine(to.FullName, Name); string oldFullname = this.FullName; Directory.Move(FullName, destname); FS.Refs.Remove(oldFullname); ((DirectoryImplementation)Parent).IntDirectories.Remove(this); to.IntDirectories.Add(this); Parent = destination; FS.Refs[FullName] = this; return(await Task.FromResult(new FileSystemResult())); }
public static void Move(string sourcePath, string destinationPath) { Directory.Move(sourcePath, destinationPath); }