You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
varcurrent=newFileSystem().CurrentDirectory();//create a "temp" subdirectory with extensioncurrent.SubDirectory("temp").Create();//create a "temp" subdirectory without extensioncurrent.FileSystem.DirectoryInfo.FromDirectoryName(current.FileSystem.Path.Combine(current.FullName,"temp")).Create();
File extension
varcurrent=newFileSystem().CurrentDirectory();//create a "test.txt" file with extensionusing(varstream=current.File("test.txt").Create())stream.Dispose();//create a "test.txt" file without extensionusing(varstream=current.FileSystem.FileInfo.FromFileName(current.FileSystem.Path.Combine(current.FullName,"test.txt")).Create())stream.Dispose();
Automatic cleanup with Disposable extensions
Use CreateDisposableDirectory or CreateDisposableFile to create a IDirectoryInfo or IFileInfo that's automatically
deleted when the returned IDisposable is disposed.
varfs=newFileSystem();//with extensionusing(fs.CreateDisposableDirectory(outIDirectoryInfodir)){Console.WriteLine($"This directory will be deleted when control leaves the using block: '{dir.FullName}'");}//without extensionvartemp=fs.Path.GetTempPath();varfileName=fs.Path.GetRandomFileName();varpath=fs.Path.Combine(temp,fileName);try{IDirectoryInfodir=fs.Directory.CreateDirectory(path);Console.WriteLine($"This directory will be deleted in the finally block: '{dir.FullName}'");}finally{fs.Directory.Delete(path,recursive:true);}
IDirectoryInfo.CopyTo extension
varfs=newFileSystem();varcurrent=fs.CurrentDirectory();//sourcevarsource=current.SubDirectory("source");source.Create();//make sure the source directory exists//destinationvardest=current.SubDirectory("destination");//copysource.CopyTo(dest,recursive:true);
About
Convenience functionality on top of System.IO.Abstractions