### Getting and Displaying FileSystemEntryInfo for a Directory in AlphaFS PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md Similar to the file example, this snippet retrieves a `FileSystemEntryInfo` object, but for a directory, using `Alphaleonis.Win32.Filesystem.File.GetFileSystemEntryInfo`. It then displays the object's properties, providing detailed attributes and information about the directory. ```PowerShell # Get a FileSystemEntryInfo object of a directory. PS C:\> $fsei = [Alphaleonis.Win32.Filesystem.File]::GetFileSystemEntryInfo($Env:WinDir) PS C:\> $fsei ``` -------------------------------- ### Getting Overloaded Methods of AlphaFS Directory Copy PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md This example shows how to retrieve the various overloaded definitions for a specific static method, such as `Copy`, from the AlphaFS `Alphaleonis.Win32.Filesystem.Directory` class in PowerShell. This is useful for understanding the different ways a method can be called and the parameters it accepts. ```PowerShell [Alphaleonis.Win32.Filesystem.Directory]::Copy ``` -------------------------------- ### Getting Operating System Information with AlphaFS PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md This snippet shows how to access various properties of the operating system using the AlphaFS `OperatingSystem` class in PowerShell. It demonstrates retrieving server status, WOW64 process status, OS version details, processor architecture, service pack version, OS name, and checking if the OS is at least a specific version. ```powershell [Alphaleonis.Win32.OperatingSystem]::IsServer ``` ```powershell [Alphaleonis.Win32.OperatingSystem]::IsWow64Process ``` ```powershell [Alphaleonis.Win32.OperatingSystem]::OSVersion ``` ```powershell [Alphaleonis.Win32.OperatingSystem]::ProcessorArchitecture ``` ```powershell [Alphaleonis.Win32.OperatingSystem]::ServicePackVersion ``` ```powershell [Alphaleonis.Win32.OperatingSystem]::VersionName ``` ```powershell [Alphaleonis.Win32.OperatingSystem]::IsAtLeast([Alphaleonis.Win32.OperatingSystem+EnumOsName]::WindowsServer2003) ``` -------------------------------- ### Comparing AlphaFS and System.IO DriveInfo in PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md This snippet contrasts the information available from the standard .NET `System.IO.DriveInfo` class with the richer details provided by the AlphaFS `Alphaleonis.Win32.Filesystem.DriveInfo` class. It shows how to instantiate both and demonstrates accessing basic properties from the standard class. ```powershell [System.IO.DriveInfo]('C') ``` -------------------------------- ### Getting and Displaying FileSystemEntryInfo for a File in AlphaFS PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md This example shows how to retrieve a `FileSystemEntryInfo` object for a specific file using the `Alphaleonis.Win32.Filesystem.File.GetFileSystemEntryInfo` method. It then demonstrates how to check the object's type and display its detailed properties, providing comprehensive information about the file. ```PowerShell # Get a FileSystemEntryInfo object of a file. PS C:\> $fsei = [Alphaleonis.Win32.Filesystem.File]::GetFileSystemEntryInfo($Env:WinDir + '\notepad.exe') PS C:\> $fsei.GetType() PS C:\> $fsei ``` -------------------------------- ### Enumerating Files and Directories with AlphaFS EnumerateXxx PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md These examples illustrate using the `EnumerateDirectories` and `EnumerateFileSystemEntries` methods from the AlphaFS `Directory` class to list directories or all entries. It shows how to specify search patterns and options like `AllDirectories` and notes that `EnumerateXxx` methods are generally more performant for large lists than `GetXxx` methods. ```PowerShell # Get all root folders from the Windows folder, starting with an 'a' PS C:\> [Alphaleonis.Win32.Filesystem.Directory]::EnumerateDirectories($Env:WinDir, 'a*') # Get all files and folders from a network share. PS C:\> $AlphaFSDir::EnumerateFileSystemEntries('\\server\share', '*', [System.IO.SearchOption]::AllDirectories) ``` -------------------------------- ### Importing AlphaFS Assembly in PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/intro.md This section demonstrates two methods for loading the AlphaFS .NET assembly into a PowerShell session. Method 1 uses `Import-Module`, which is standard for loading modules and assemblies. Method 2 uses `.NET Reflection` directly via `[Reflection.Assembly]::LoadFile`, which loads the assembly into the current application domain. Both methods make the AlphaFS classes available. ```PowerShell Import-Module -Name 'C:\AlphaFS 2.2\Lib\Net4.0\AlphaFS.dll' ``` ```PowerShell $assembly = [Reflection.Assembly]::LoadFile('C:\AlphaFS 2.2\Lib\Net4.0\AlphaFS.dll') $assembly ``` -------------------------------- ### Creating and Displaying DirectoryInfo Object with AlphaFS PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md This command demonstrates how to create a `DirectoryInfo` object for a specific directory using `New-Object` with the AlphaFS `Alphaleonis.Win32.Filesystem.DirectoryInfo` type. It then shows how to verify the object's type and display its properties, which provide details about the directory. ```PowerShell # Get a DirectoryInfo object of a directory. PS C:\> $dirInfo = New-Object -TypeName Alphaleonis.Win32.Filesystem.DirectoryInfo($Env:WinDir) PS C:\> $dirInfo.GetType() PS C:\> $dirInfo ``` -------------------------------- ### Creating Directories and Using Short References in AlphaFS PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md These commands illustrate how to create a directory using the static `CreateDirectory` method from the AlphaFS `Directory` class. It also shows how to assign the class type to a PowerShell variable for shorter, more convenient referencing in subsequent calls, like creating a compressed directory. ```PowerShell # Call the CreateDirectory() method from the Directory class. PS C:\> [Alphaleonis.Win32.Filesystem.Directory]::CreateDirectory('C:\MyFolder') # If you prefer a shorter reference, assign the TypeName to a PowerShell variable. PS C:\> $AlphaFSDir = [Alphaleonis.Win32.Filesystem.Directory] # And then use the short form. # Create a compressed directory. PS C:\> $AlphaFSDir::CreateDirectory('C:\MyCompressedFolder', $True) ``` -------------------------------- ### Path.GetFullPath() Comparison with GlobalRoot Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/differences.md Shows how System.IO.Path.GetFullPath() throws an ArgumentException when the path starts with \\?\GLOBALROOT, while AlphaFS returns the input path as is. ```C# Input Path: `\\?\GLOBALROOT\device\harddisk0\partition1\` System.IO: `Caught [System.IO] System.ArgumentException: [Paths that begin with \\?\GlobalRoot are internal to the kernel and should not be opened by managed applications.` AlphaFS: Returns Input Path: `\\?\GLOBALROOT\device\harddisk0\partition1\` ``` -------------------------------- ### Showing Static Methods of AlphaFS Directory Class PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md This snippet demonstrates how to use the standard PowerShell `Get-Member` cmdlet with the `-Static` flag to inspect and list all available static methods on the AlphaFS `Alphaleonis.Win32.Filesystem.Directory` class. It helps discover available file system operations provided by AlphaFS. ```PowerShell [Alphaleonis.Win32.Filesystem.Directory] | gm -Static -MemberType Method ``` -------------------------------- ### Copying a Directory Recursively using DirectoryInfo CopyTo in AlphaFS PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md This example demonstrates an alternative way to copy a directory recursively by using the `CopyTo` method available on an `Alphaleonis.Win32.Filesystem.DirectoryInfo` instance. It shows how to call `CopyTo` with just the destination or with additional copy options. ```PowerShell PS C:\> $dirInfo.CopyTo($destination) PS C:\> $dirInfo.CopyTo($destination, $copyOptions) ``` -------------------------------- ### Copying a File with AlphaFS File.Copy PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md This simple snippet illustrates how to copy a file from a source path to a destination path using the static `Alphaleonis.Win32.Filesystem.File.Copy` method. This is a basic file operation provided by the AlphaFS library. ```PowerShell # Copy file. PS C:\> [Alphaleonis.Win32.Filesystem.File]::Copy('C:\Folder\oldFile.txt', 'D:\Folder\newFile.txt') ``` -------------------------------- ### Getting Next Available Free Drive Letter with AlphaFS PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md This snippet demonstrates how to use the static method `GetFreeDriveLetter` from the AlphaFS `DriveInfo` class to programmatically find the next available drive letter on the system. ```powershell $letter = [Alphaleonis.Win32.Filesystem.DriveInfo]::GetFreeDriveLetter() ``` ```powershell $letter ``` -------------------------------- ### Enumerating Network Shares from a Host with AlphaFS PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md This snippet demonstrates how to use the AlphaFS `Alphaleonis.Win32.Network.Host.EnumerateShares` method to list network shares available on a specified host (in this case, the local computer name via `$Env:COMPUTERNAME`). It retrieves detailed information about each share. ```PowerShell PS C:\> [Alphaleonis.Win32.Network.Host]::EnumerateShares($Env:COMPUTERNAME, $True) ``` -------------------------------- ### Getting .NET Version in PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/intro.md This snippet uses the built-in `$PSVersionTable` variable to display details about the PowerShell environment, specifically focusing on the CLR (Common Language Runtime) version, which corresponds to the .NET framework version being used. It's important for ensuring compatibility with the correct AlphaFS assembly. ```PowerShell $PSVersionTable.CLRVersion ``` -------------------------------- ### Getting Aggregated Directory Properties with AlphaFS PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md This snippet demonstrates how to use the AlphaFS `Directory.GetProperties` method to retrieve aggregated information about a folder, including counts of different file attributes and the total size of the directory structure. It shows how to set enumeration options and path format before calling the method and displaying the results. ```powershell $dirEnumOptions = [Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions]::Recursive -bor [Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions]::SkipReparsePoints -bor [Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions]::ContinueOnException ``` ```powershell $pathFormat = [Alphaleonis.Win32.Filesystem.PathFormat]::FullPath ``` ```powershell $properties = [Alphaleonis.Win32.Filesystem.Directory]::GetProperties('C:\', $dirEnumOptions, $pathFormat) ``` ```powershell $properties.Size ``` ```powershell $properties | Format-Table -AutoSize ``` -------------------------------- ### Copying a Directory Recursively with AlphaFS Directory.Copy PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md This snippet shows how to copy a directory recursively using the static `Alphaleonis.Win32.Filesystem.Directory.Copy` method. It includes setting copy options like `FailIfExists` and specifying the source and destination paths for the recursive copy operation. ```PowerShell # Set copy options. PS C:\> $copyOptions = [Alphaleonis.Win32.Filesystem.CopyOptions]::FailIfExists # Set source and destination directories. PS C:\> $source = 'C:\sourceDir' PS C:\> $destination = 'C:\destinationDir' # Copy directory recursively. PS C:\> [Alphaleonis.Win32.Filesystem.Directory]::Copy($source, $destination, $copyOptions) ``` -------------------------------- ### Removing File with Trailing Space using AlphaFS PathFormat PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md This crucial example shows how AlphaFS can delete files with names ending in a space, which is not possible with standard .NET methods. By using the `[Alphaleonis.Win32.Filesystem.PathFormat]::FullPath` parameter with the `Alphaleonis.Win32.Filesystem.File.Delete` method, AlphaFS bypasses this limitation and allows deletion using the verbatim path. ```PowerShell # Remove file, use path as is. # .NET does not allow for a file name to end with a space or a dot. # Use the [Alphaleonis.Win32.Filesystem.PathFormat]::FullPath parameter to bypass this. PS C:\> [Alphaleonis.Win32.Filesystem.File]::Delete('C:\Temp\file ', [Alphaleonis.Win32.Filesystem.PathFormat]::FullPath) ``` -------------------------------- ### Accessing Extended Drive Information with AlphaFS PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md Building upon the comparison, this snippet demonstrates instantiating the AlphaFS `DriveInfo` object and accessing its expanded set of properties, including detailed disk space information (`DiskSpaceInfo`) and volume-specific properties (`VolumeInfo`). It highlights the additional data available through AlphaFS for file system analysis. ```powershell $driveInfo = [Alphaleonis.Win32.Filesystem.DriveInfo]('C') ``` ```powershell $driveInfo ``` ```powershell $driveInfo.DiskSpaceInfo ``` ```powershell $driveInfo.VolumeInfo ``` -------------------------------- ### Browsing Restricted Folders using PrivilegeEnabler AlphaFS PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md This snippet shows how to use the AlphaFS `PrivilegeEnabler` class to temporarily elevate security privileges, specifically the 'Backup' privilege, which is often required to access system folders like `C:\Windows\CSC`. It includes a `Try/Finally` block to ensure the privilege enabler is properly disposed. ```powershell $privilegeEnabler = $Null Try { $privilege = [Alphaleonis.Win32.Security.Privilege]::Backup $privilegeEnabler = New-Object Alphaleonis.Win32.Security.PrivilegeEnabler($privilege) Dir -Recurse C:\Windows\CSC } Finally { If ($Null -ne $privilegeEnabler) { $privilegeEnabler.Dispose() } } ``` -------------------------------- ### Deleting Files with Long Paths and PathFormat (PowerShell) Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/intro.md Illustrates how to use the `PathFormat` parameter with the `Delete` method in AlphaFS to improve performance by skipping path resolution and validation. It involves getting the long path using `GetLongPath` and then calling `Delete` with the `LongFullPath` option. ```PowerShell PS C:\\> $longPath = [Alphaleonis.Win32.Filesystem.Path]::GetLongPath('\\\\host\\c$\\Data\\test.txt')` PS C:\\> $longPath \\?\UNC\\host\\c$\\Data\\test.txt PS C:\\> [Alphaleonis.Win32.Filesystem.File]::Delete($longPath, $True, [Alphaleonis.Win32.Filesystem.PathFormat]::LongFullPath) ``` -------------------------------- ### Overcoming Path Too Long with AlphaFS EnumerateFileSystemEntries PowerShell Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/powershell/examples.md This snippet contrasts the standard `Get-ChildItem` cmdlet, which is prone to 'Path Too Long' errors, with the AlphaFS `Directory.EnumerateFileSystemEntries` method. The AlphaFS method is demonstrated as a solution to reliably enumerate file system entries in deep directory structures that exceed standard path length limits. ```PowerShell # How people learn about "Path Too Long". PS C:\> Get-ChildItem -Recurse -Path $folderPath # How salvation is offered. PS C:\> [Alphaleonis.Win32.Filesystem.Directory]::EnumerateFileSystemEntries($folderPath, '*', [System.IO.SearchOption]::AllDirectories) ``` -------------------------------- ### Path Root Retrieval Comparison: AlphaFS vs System.IO Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/differences.md This code demonstrates the comparison between System.IO and AlphaFS libraries for retrieving the root path of various input paths. It showcases how each library handles different path formats, including local paths, UNC paths, and paths with the \\?\ prefix. ```C# /* Example Usage: Input Path: [.] System.IO : [] AlphaFS : [] Input Path: [.zip] System.IO : [] AlphaFS : [] Input Path: [C:\\test.txt] System.IO : [C:\\] AlphaFS : [C:\\] Input Path: [C:/test.txt] System.IO : [C:\\] AlphaFS : [C:\\] Input Path: [\] System.IO : [\] AlphaFS : [\] Input Path: [\\Program Files\\Microsoft Office] System.IO : [\] AlphaFS : [\] Input Path: [\\?\GLOBALROOT\\device\\harddisk0\\partition1\\] Caught [System.IO] System.ArgumentException: [Paths that begin with \\?\GlobalRoot are internal to the kernel and should not be opened by managed applications.] System.IO : [null] AlphaFS : [\\?\GLOBALROOT] Input Path: [\\?\Volume{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}\\Program Files\\notepad.exe] System.IO : [\\?\Volume{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}] AlphaFS : [\\?\Volume{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}] Input Path: [Program Files\\Microsoft Office] System.IO : [] AlphaFS : [] Input Path: [C] System.IO : [] AlphaFS : [] Input Path: [C:] System.IO : [C:] AlphaFS : [C:] Input Path: [C:\\] System.IO : [C:\\] AlphaFS : [C:\\] Input Path: [C:\\a] System.IO : [C:\\] AlphaFS : [C:\\] Input Path: [C:\\a\\] System.IO : [C:\\] AlphaFS : [C:\\] Input Path: [C:\\a\\b] System.IO : [C:\\] AlphaFS : [C:\\] Input Path: [C:\\a\\b\\] System.IO : [C:\\] AlphaFS : [C:\\] Input Path: [C:\\a\\b\\c] System.IO : [C:\\] AlphaFS : [C:\\] Input Path: [C:\\a\\b\\c\\] System.IO : [C:\\] AlphaFS : [C:\\] Input Path: [C:\\a\\b\\c\\f] System.IO : [C:\\] AlphaFS : [C:\\] Input Path: [C:\\a\\b\\c\\f.] System.IO : [C:\\] AlphaFS : [C:\\] Input Path: [C:\\a\\b\\c\\f.t] System.IO : [C:\\] AlphaFS : [C:\\] Input Path: [C:\\a\\b\\c\\f.tx] System.IO : [C:\\] AlphaFS : [C:\\] Input Path: [C:\\a\\b\\c\\f.txt] System.IO : [C:\\] AlphaFS : [C:\\] Input Path: [\\?\\Program Files\\Microsoft Office] System.IO : [\\?\\Program Files] AlphaFS : [\\?\\Program Files] Input Path: [\\?\\C] System.IO : [\\?\\C] AlphaFS : [\\?\\C] Input Path: [\\?\\C:] System.IO : [\\?\\C:] AlphaFS : [\\?\\C:] Input Path: [\\?\\C:\\] System.IO : [\\?\\C:] AlphaFS : [\\?\\C:] Input Path: [\\?\\C:\\a] System.IO : [\\?\\C:] AlphaFS : [\\?\\C:] Input Path: [\\?\\C:\\a\\] System.IO : [\\?\\C:] AlphaFS : [\\?\\C:] Input Path: [\\?\\C:\\a\\b] System.IO : [\\?\\C:] AlphaFS : [\\?\\C:] Input Path: [\\?\\C:\\a\\b\\] System.IO : [\\?\\C:] AlphaFS : [\\?\\C:] Input Path: [\\?\\C:\\a\\b\\c] System.IO : [\\?\\C:] AlphaFS : [\\?\\C:] Input Path: [\\?\\C:\\a\\b\\c\\] System.IO : [\\?\\C:] AlphaFS : [\\?\\C:] Input Path: [\\?\\C:\\a\\b\\c\\f] System.IO : [\\?\\C:] AlphaFS : [\\?\\C:] Input Path: [\\?\\C:\\a\\b\\c\\f.] System.IO : [\\?\\C:] AlphaFS : [\\?\\C:] Input Path: [\\?\\C:\\a\\b\\c\\f.t] System.IO : [\\?\\C:] AlphaFS : [\\?\\C:] Input Path: [\\?\\C:\\a\\b\\c\\f.tx] System.IO : [\\?\\C:] AlphaFS : [\\?\\C:] Input Path: [\\?\\C:\\a\\b\\c\\f.txt] System.IO : [\\?\\C:] AlphaFS : [\\?\\C:] Input Path: [\\\\SERVER001\\Share] System.IO : [\\\\SERVER001\\Share] AlphaFS : [\\\\SERVER001\\Share] Input Path: [\\\\SERVER001\\Share\\] System.IO : [\\\\SERVER001\\Share] AlphaFS : [\\\\SERVER001\\Share] Input Path: [\\\\SERVER001\\Share\\d] System.IO : [\\\\SERVER001\\Share] AlphaFS : [\\\\SERVER001\\Share] Input Path: [\\\\SERVER001\\Share\\d1] System.IO : [\\\\SERVER001\\Share] AlphaFS : [\\\\SERVER001\\Share] Input Path: [\\\\SERVER001\\Share\\d1\\] System.IO : [\\\\SERVER001\\Share] AlphaFS : [\\\\SERVER001\\Share] Input Path: [\\\\SERVER001\\Share\\d1\\d] System.IO : [\\\\SERVER001\\Share] AlphaFS : [\\\\SERVER001\\Share] */ ``` -------------------------------- ### Parsing Extended UNC Paths with AlphaFS and System.IO Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/differences.md This snippet demonstrates how AlphaFS and System.IO handle extended UNC paths prefixed with \\?\UNC. It highlights that System.IO throws an ArgumentException for these paths, while AlphaFS successfully parses them. ```C# Input Path: [\\?\UNC\\SERVER001\\Share] Caught [System.IO] System.ArgumentException: [Illegal characters in path.] System.IO : [null] AlphaFS : [\\\\SERVER001\\Share] ``` ```C# Input Path: [\\?\UNC\\SERVER001\\Share\\d1\\d2\\fil] Caught [System.IO] System.ArgumentException: [Illegal characters in path.] System.IO : [null] AlphaFS : [\\\\SERVER001\\Share] ``` -------------------------------- ### Path.GetPathRoot() Comparison Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/differences.md Demonstrates the difference in output between System.IO and AlphaFS for Path.GetPathRoot() when using UNC long path format. System.IO incorrectly returns '\\?\UNC' while AlphaFS correctly returns the full UNC path. ```C# Input Path: [\\SERVER001\Share] System.IO : [\\SERVER001\Share] AlphaFS : [\\SERVER001\Share] # Use UNC long path format. Input Path: [\\?\UNC\SERVER001\Share] System.IO : [\\?\UNC] AlphaFS : [\\?\UNC\SERVER001\Share] ``` -------------------------------- ### Directory.GetDirectoryRoot() Comparison Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/differences.md Illustrates the difference in behavior between System.IO and AlphaFS for Directory.GetDirectoryRoot() when using long path format. System.IO throws an ArgumentException, while AlphaFS correctly returns the root directory. ```C# Input Path: [\\?\C:] Caught [System.IO] System.ArgumentException: [Illegal characters in path.] System.IO : [null] AlphaFS : [C:] # Use UNC long path format. Input Path: [\\?\UNC\SERVER001\Share\folder2] Caught [System.IO] System.ArgumentException: [Illegal characters in path.] System.IO : [null] AlphaFS : [\\SERVER001\Share] ``` -------------------------------- ### Parsing Local Paths with AlphaFS and System.IO Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/differences.md This snippet demonstrates how AlphaFS and System.IO handle local file paths. It shows cases where System.IO throws an ArgumentException for paths containing illegal characters, while AlphaFS successfully processes them. ```C# Input Path: [\\?\C:\\a\\b\\c\\f.tx] Caught [System.IO] System.ArgumentException: [Illegal characters in path.] System.IO : [null] AlphaFS : [C:\\] ``` ```C# Input Path: [\\?\C:\\a\\b\\c\\f.txt] Caught [System.IO] System.ArgumentException: [Illegal characters in path.] System.IO : [null] AlphaFS : [C:\\] ``` -------------------------------- ### Parsing UNC Paths with AlphaFS and System.IO Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/differences.md This snippet illustrates how AlphaFS and System.IO handle UNC paths. It shows that System.IO returns the server share name, while AlphaFS returns the full UNC path. ```C# Input Path: [\\\\SERVER001\\Share] System.IO : [\\\\SERVER001\\Share] AlphaFS : [\\\\SERVER001\\Share] ``` ```C# Input Path: [\\\\SERVER001\\Share\\d1\\d2\\file.ext] System.IO : [\\\\SERVER001\\Share] AlphaFS : [\\\\SERVER001\\Share] ``` -------------------------------- ### Directory.Exists() Behavior with Long Paths Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/differences.md Explains how System.IO.Directory.Exists() throws an ArgumentException and returns False when encountering long path notation (\\?\), even if the directory exists, while AlphaFS correctly returns True. ```C# `System.IO.Directory.Exists()` internally throws a `System.ArgumentException: Illegal characters in path` when encountering the long path notation: `\\?\` and returns `False`, even if the folder exists. AlphaFS returns `True` when the folder exists. This also applies to `System.IO.Path.GetFullPath()` ``` -------------------------------- ### Inspecting Delete Method Overloads (PowerShell) Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/intro.md Demonstrates how to inspect the available overloads of the `Delete` method in AlphaFS using PowerShell to identify the overload that supports the `PathFormat` parameter. This allows for optimized file operations by skipping path resolution and validation checks. ```PowerShell PS C:\\> [Alphaleonis.Win32.Filesystem.File]::Delete ``` -------------------------------- ### Deleting Files with Long Paths in AlphaFS (C#) Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/intro.md Demonstrates how AlphaFS handles long paths automatically when deleting files, eliminating the need for manual prefixing. It showcases the usage of the `Alphaleonis.Win32.Filesystem.File.Delete` method with various path formats. ```CSharp // Will all be handled as a long path by AlphaFS. Alphaleonis.Win32.Filesystem.File.Delete("C:\\Data\\test.txt"); Alphaleonis.Win32.Filesystem.File.Delete("\\\\?\\C:\\Data\\test.txt"); Alphaleonis.Win32.Filesystem.File.Delete("\\\\host\\c$\\Data\\test.txt"); Alphaleonis.Win32.Filesystem.File.Delete("\\\\?\\UNC\\host\\c$\\Data\\test.txt"); ``` -------------------------------- ### Transactional File Write with KernelTransaction in C# Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/intro.md This code demonstrates how to perform a transactional file write using KernelTransaction within a TransactionScope. It creates a new KernelTransaction associated with the current System.Transactions.Transaction. The WriteAllText method is then used to write to a file within the transaction. If an exception occurs, the transaction is rolled back, and no changes are committed to the file system. ```C# using (var ts = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.RequiresNew)) { // KernelTransaction is in AlphaFS. var kt = new KernelTransaction(System.Transactions.Transaction.Current); // Append "hello" to text file named "text.txt" Alphaleonis.Win32.Filesystem.File.WriteAllText(kt, "text.txt", "hello"); // No text appended because exception will be thrown. throw new Exception("oops"); ts.Complete(); } ``` -------------------------------- ### Deleting Files with Long Paths in AlphaFS (PowerShell) Source: https://github.com/alphaleonis/alphafs/blob/develop/docs/articles/intro.md Shows how to delete files with long paths using AlphaFS methods in PowerShell. It requires importing the AlphaFS DLL and then calling the `Delete` method with different path formats. ```PowerShell PS C:\\> [Alphaleonis.Win32.Filesystem.File]::Delete('C:\\Data\\test.txt') PS C:\\> [Alphaleonis.Win32.Filesystem.File]::Delete('\\\\?\\UNC\\host\\c$\\Data\\test.txt') ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.