### Build Faster OS from Source Source: https://github.com/ambeteco/faster-os/blob/main/README.md These steps outline how to build the Faster OS library from its source code, typically for development or if direct installation from PyPI is not desired. ```bash # 1. Clone the repository git clone https://github.com/American-Best-Technologies-Company/faster-os.git # 2. Navigate into the cloned directory cd faster-os # 3. Run the build script python3 setup.py build_ext # 4. Verify installation python -c "import faster_os; print('Faster OS installed successfully')" ``` -------------------------------- ### Install Faster OS via Pip Source: https://github.com/ambeteco/faster-os/blob/main/README.md This command installs or upgrades the Faster OS library using pip, the Python package installer. ```bash pip install faster_os --upgrade ``` -------------------------------- ### Install and Use Faster OS as os.path Replacement (Python) Source: https://context7.com/ambeteco/faster-os/llms.txt Demonstrates how to install Faster OS via pip and import it as a direct replacement for Python's standard os module. It shows basic usage of path manipulation functions, highlighting cross-platform compatibility. ```python # Install from PyPI # pip install faster_os --upgrade # Import as a drop-in replacement for os import faster_os as os # Or import directly import faster_os # Works cross-platform - automatically detects Windows vs Unix faster_os.path.join('/', 'some', 'path') # Returns: '/some/path' faster_os.path.split('/some/test/path') # Returns: ('/some/test', 'path') ``` -------------------------------- ### Python Faster OS Path Splitdrive Example Source: https://github.com/ambeteco/faster-os/blob/main/README.md Demonstrates the `splitdrive` function from Faster OS, which separates a path into a drive specification and the rest of the path. This is a high-performance version of `os.path.splitdrive`. ```python import faster_os # Example with a Windows drive print(faster_os.path.splitdrive('C:\\HELLO WORLD\\SOME PATH')) # Expected output: ('C:', '\\HELLO WORLD\\SOME PATH') # Example with a UNC path print(faster_os.path.splitdrive('\\machine\mountpoint\directory\etc\')) # Expected output: ('\\machine\mountpoint', '\directory\etc\') ``` -------------------------------- ### Python Faster OS Path Splitext Example Source: https://github.com/ambeteco/faster-os/blob/main/README.md Shows how to use the `splitext` function from Faster OS to divide a pathname into a root and an extension. This function is a faster alternative to `os.path.splitext`. ```python import faster_os # Example with a backslash in the filename print(faster_os.path.splitext('hello world\123.ext')) # Expected output: ('hello world\123', '.ext') # Example with a Windows drive path print(faster_os.path.splitext('C:\\sample_photo.jpg')) # Expected output: ('C:\\sample_photo', '.jpg') ``` -------------------------------- ### Python Faster OS Path Join Example Source: https://github.com/ambeteco/faster-os/blob/main/README.md Demonstrates how to use the `join` function from the Faster OS library to construct file paths. This function is optimized for speed and works similarly to the standard `os.path.join`. ```python import faster_os # Example for UNIX-like paths print(faster_os.path.join('/', 'some', 'path')) # Expected output: '/some/path' # Example for Windows paths print(faster_os.path.join('C:\\', 'Windows\\System32', 'LogFiles')) # Expected output: 'C:\\Windows\\System32\\LogFiles' ``` -------------------------------- ### Python Faster OS Path Split Example Source: https://github.com/ambeteco/faster-os/blob/main/README.md Illustrates the usage of the `split` function from the Faster OS library for separating a path into its directory and file components. It mirrors the functionality of `os.path.split` but with enhanced performance. ```python import faster_os # Example for UNIX-like paths print(faster_os.path.split('/some/test/path')) # Expected output: ('/some/test', 'path') # Example for Windows paths print(faster_os.path.split('C:\\Users\\User\\Desktop')) # Expected output: ('C:\\Users\\User', 'Desktop') ``` -------------------------------- ### Join Path Components with Faster OS (Python) Source: https://context7.com/ambeteco/faster-os/llms.txt Shows how to use `faster_os.path.join` to concatenate multiple path components into a single path string, using the appropriate separator for the operating system. Includes examples for both Unix-like and Windows systems, and highlights performance gains. ```python import faster_os # Unix/Linux path joining path = faster_os.path.join('/', 'home', 'user', 'documents') print(path) # Output: '/home/user/documents' path = faster_os.path.join('/var', 'log', 'system.log') print(path) # Output: '/var/log/system.log' # Windows path joining path = faster_os.path.join('C:\', 'Windows', 'System32', 'drivers') print(path) # Output: 'C:\Windows\System32\drivers' path = faster_os.path.join('C:\Users', 'User', 'Desktop') print(path) # Output: 'C:\Users\User\Desktop' # Empty string handling path = faster_os.path.join('', 'relative', 'path') print(path) # Output: 'relative/path' # Performance: 1530% faster than os.path.join # Process 1M paths in 14 seconds vs 3m 20s with standard os ``` -------------------------------- ### Split Path into Directory and Basename with Faster OS (Python) Source: https://context7.com/ambeteco/faster-os/llms.txt Illustrates the usage of `faster_os.path.split` for separating a path into its directory and basename components. Examples cover Unix-like and Windows path formats, and note the performance improvements over the standard library. ```python import faster_os # Unix/Linux examples result = faster_os.path.split('/home/user/documents/file.txt') print(result) # Output: ('/home/user/documents', 'file.txt') result = faster_os.path.split('/home/user/documents/') print(result) # Output: ('/home/user/documents', '') result = faster_os.path.split('/single') print(result) # Output: ('/', 'single') # Windows examples result = faster_os.path.split('C:\Users\User\Desktop\file.pdf') print(result) # Output: ('C:\Users\User', 'Desktop') result = faster_os.path.split('C:\Windows\System32') print(result) # Output: ('C:\Windows', 'System32') # Performance: 1190% faster than os.path.split # Process 1M paths in 18 seconds vs 4m 43s with standard os ``` -------------------------------- ### Compute Relative Path with faster_os.path.relpath Source: https://context7.com/ambeteco/faster-os/llms.txt Calculates the relative path from a starting directory to a target path. Handles paths that require traversing up the directory tree. Can utilize the current working directory if no start path is specified. Offers substantial performance improvements over os.path.relpath. ```python import faster_os import os # Relative path from root to target relpath = faster_os.path.relpath('/usr/local/bin', '/usr') print(relpath) # Output: local/bin relpath = faster_os.path.relpath('/home/user/documents', '/home/user') print(relpath) # Output: documents relpath = faster_os.path.relpath('/var/log/system.log', '/var') print(relpath) # Output: log/system.log # Different branches requiring parent traversal relpath = faster_os.path.relpath('/usr/local/lib', '/var/log') print(relpath) # Output: ../../usr/local/lib relpath = faster_os.path.relpath('/home/user/documents', '/home/admin') print(relpath) # Output: ../user/documents # No root specified (uses current working directory) os.chdir('/home/user') relpath = faster_os.path.relpath('/home/user/documents/file.txt') print(relpath) # Output: documents/file.txt # Windows examples relpath = faster_os.path.relpath('C:\Users\User\Documents', 'C:\Users') print(relpath) # Output: User\Documents ``` -------------------------------- ### Split Path into Root and Extension (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Splits a path string into two parts: the root (everything except the final extension) and the extension. The extension is typically the part of the filename starting from the last dot. This mirrors os.path.splitext. ```python import faster_os.path root, ext = faster_os.path.splitext('document.pdf') print(f'Root: {root}, Extension: {ext}') ``` -------------------------------- ### Apply Basename to Multiple Paths (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Applies the `basename` function to each path in an iterable. It returns a list of base names extracted from the corresponding input paths. This provides a way to get multiple base names efficiently. ```python import faster_os.path paths_to_basename = ['/usr/bin/python', '/etc/config.conf'] basenames = faster_os.path.multi_basename(paths_to_basename) print(basenames) ``` -------------------------------- ### Get Absolute Path with Faster OS Source: https://github.com/ambeteco/faster-os/blob/main/README.md The abspath function returns an absolute version of a path. It resolves relative paths based on the current working directory. ```python import faster_os faster_os.path.abspath('Desktop') # Expected output: 'D:\Libraries\Desktop\Pys\Big\FasterOS\Desktop' faster_os.path.abspath('Appdata\Local') # Expected output: 'D:\Libraries\Desktop\Pys\Big\FasterOS\Appdata\Local' ``` -------------------------------- ### Get Base Name of Path (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Extracts the base name (the final component) from a given path string. For example, the base name of '/usr/local/bin/python' is 'python'. This function is equivalent to os.path.basename. ```python import faster_os.path base = faster_os.path.basename('/usr/local/bin/python') print(f'Base name: {base}') ``` -------------------------------- ### Get Directory Name of Path (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Extracts the directory name from a given path string. For example, the directory name of '/usr/local/bin/python' is '/usr/local/bin'. This function mirrors os.path.dirname. ```python import faster_os.path dir = faster_os.path.dirname('/usr/local/bin/python') print(f'Directory name: {dir}') ``` -------------------------------- ### Get Base Name of Path with Faster OS Source: https://github.com/ambeteco/faster-os/blob/main/README.md The basename function returns the final component of a pathname. It effectively strips the directory path. ```python import faster_os faster_os.path.basename('C:\HELLO WORLD\SOME PATH') # Expected output: 'SOME PATH' faster_os.path.basename('C:\faster-os') # Expected output: 'faster-os' ``` -------------------------------- ### Split Path into Directory and Base Name (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Splits a path string into a tuple containing the directory part and the base name part. For example, 'a/b/c.txt' would be split into ('a/b', 'c.txt'). This function is analogous to os.path.split. ```python import faster_os.path dirname, basename = faster_os.path.split('a/b/c.txt') print(f'Directory: {dirname}, Base Name: {basename}') ``` -------------------------------- ### Compute Relative Paths in Batch with faster_os.path.multi_relpath Source: https://context7.com/ambeteco/faster-os/llms.txt Computes the relative path for multiple pairs of paths efficiently. It takes a list of tuples, where each tuple contains a target path and a starting path, and returns a list of corresponding relative paths. This function is optimized for batch operations and shows significant performance gains for large datasets compared to individual calls. ```python import faster_os relpath_pairs = [ ('/usr/local/bin', '/usr'), ('/home/user/documents', '/home/user'), ('/var/log/system.log', '/var') ] relpaths = faster_os.path.multi_relpath(relpath_pairs) print(relpaths) # Output: ['local/bin', 'documents', 'log/system.log'] ``` -------------------------------- ### Remove Directories Recursively with Faster OS Source: https://github.com/ambeteco/faster-os/blob/main/README.md The removedirs function removes directories recursively. It starts from the innermost directory and works its way up, removing empty parent directories. ```python import faster_os # Example of removing a directory and its parents if empty # faster_os.removedirs('C:\\This\Path\Will\Be\Deleted') ``` -------------------------------- ### Get Directory Name of Path with Faster OS Source: https://github.com/ambeteco/faster-os/blob/main/README.md The dirname function returns the directory component of a pathname. It effectively strips the final file or directory name. ```python import faster_os faster_os.path.dirname('C:\HELLO WORLD\SOME PATH') # Expected output: 'C:\HELLO WORLD' faster_os.path.dirname('C:\faster-os') # Expected output: 'C:\' ``` -------------------------------- ### Split Drive Letter from Path (Windows) with Faster OS (Python) Source: https://context7.com/ambeteco/faster-os/llms.txt Explains and demonstrates the `faster_os.path.splitdrive` function, which is specific to Windows for separating the drive letter or UNC share from the rest of the path. Provides examples for different Windows path structures. ```python import faster_os # Windows drive letter splitting drive, path = faster_os.path.splitdrive('C:\Windows\System32') print(f"Drive: {drive}, Path: {path}") # Output: Drive: C:, Path: \Windows\System32 drive, path = faster_os.path.splitdrive('D:\Data\files') print(f"Drive: {drive}, Path: {path}") # Output: Drive: D:, Path: \Data\files ``` -------------------------------- ### Check if Path is Absolute (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Determines if a given path string represents an absolute path. An absolute path starts from the root of the file system. This function mirrors os.path.isabs. ```python import faster_os.path is_absolute = faster_os.path.isabs('/usr/local/bin') print(f'Is absolute: {is_absolute}') ``` -------------------------------- ### Recursively Remove Directories with faster_os.removedirs Source: https://github.com/ambeteco/faster-os/blob/main/README.md The `removedirs` function recursively deletes directory components starting from a given path until an error is encountered (e.g., non-empty directory, permission denied). It returns None upon successful completion or upon encountering an unrecoverable error. ```python faster_os.removedirs(path) -> None # Example: # Given path "C:\\Users\\User\\Desktop\\many\\folders\\here" # Delete "C:\\Users\\User\\Desktop\\many\\folders\\here" # Delete "C:\\Users\\User\\Desktop\\many\\folders" # Delete "C:\\Users\\User\\Desktop\\many" # Delete "C:\\Users\\User\\Desktop\" -> ERROR - return ``` -------------------------------- ### Get Absolute Path Source: https://context7.com/ambeteco/faster-os/llms.txt Demonstrates `faster_os.path.abspath` for converting a relative path into an absolute path. It uses the current working directory as the base for relative paths and handles both Unix-style and Windows-style paths, including navigating parent directories (`..`). ```python import faster_os import os # Set working directory for example os.chdir('/home/user/projects') # Relative path to absolute absolute = faster_os.path.abspath('documents/file.txt') print(absolute) # Output: /home/user/projects/documents/file.txt absolute = faster_os.path.abspath('../downloads/image.png') print(absolute) # Output: /home/user/downloads/image.png # Already absolute path absolute = faster_os.path.abspath('/usr/local/bin') print(absolute) # Output: /usr/local/bin # Windows examples os.chdir('C:\\Users\\User') absolute = faster_os.path.abspath('Desktop\\file.txt') print(absolute) # Output: C:\Users\User\Desktop\file.txt absolute = faster_os.path.abspath('..\\Public\\Documents') print(absolute) # Output: C:\Users\Public\Documents ``` -------------------------------- ### Get Absolute Path (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Resolves a given path to its absolute form. It attempts to use the operating system's API or falls back to joining the path with the current working directory. This function mirrors os.path.abspath. ```python import faster_os.path absolute_path = faster_os.path.abspath('myfile.txt') print(f'Absolute path: {absolute_path}') ``` -------------------------------- ### Recursively Remove Empty Directories with faster_os.removedirs Source: https://context7.com/ambeteco/faster-os/llms.txt Removes directories recursively starting from a given path until a non-empty directory or an error is encountered. This function is useful for cleaning up nested empty directory structures. It mimics the behavior of `os.removedirs` but may offer performance benefits or different error handling in certain scenarios. ```python import faster_os import os # Example: Assuming /tmp/test/empty/nested/deep exists and is empty # faster_os.removedirs('/tmp/test/empty/nested/deep') # Windows example # faster_os.removedirs('C:\\Temp\\Empty\\Nested\\Folders') # Practical use case with error handling try: faster_os.removedirs('/var/cache/temp/processing/session/files') print("Empty directories removed successfully") except OSError as e: print(f"Stopped at non-empty directory: {e}") ``` -------------------------------- ### Apply Expanduser to Multiple Paths (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Applies the `expanduser` function to each path in an iterable. It returns a list of paths with the user's home directory reference ('~') expanded to its full path. This provides batch expansion of user home paths. ```python import faster_os.path paths_to_expand = ['~/Documents', '~/.bashrc'] expanded_paths = faster_os.path.multi_expanduser(paths_to_expand) print(expanded_paths) ``` -------------------------------- ### Join Path Components (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Joins one or more path components into a single path string, using the appropriate platform-specific path delimiter ('/' or '\'). This is equivalent to os.path.join. ```python import faster_os.path joined_path = faster_os.path.join('dir1', 'dir2', 'file.txt') print(joined_path) ``` -------------------------------- ### Apply Join to Multiple Path Sets (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Applies the `join` function to multiple sets of path components provided in an iterable. Each inner iterable is joined into a single path. This allows for batch joining of path segments. ```python import faster_os.path path_sets = [('dir1', 'file1.txt'), ('dir2', 'subdir', 'file2.jpg')] joined_paths = faster_os.path.multi_join(path_sets) print(joined_paths) ``` -------------------------------- ### Apply Ismount to Multiple Paths (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Applies the `ismount` function to each path in an iterable. It returns a list of boolean values, where each value indicates whether the corresponding path is a mount point. This allows for batch checking of mount points. ```python import faster_os.path paths_to_check_mount = ['/', '/mnt/data'] is_mount_list = faster_os.path.multi_ismount(paths_to_check_mount) print(is_mount_list) ``` -------------------------------- ### Join Paths Efficiently with Faster OS Multi-Function Source: https://github.com/ambeteco/faster-os/blob/main/README.md The multi_join function is designed for processing extra-large lists of path components efficiently. It takes a list of tuples, where each tuple contains path segments to be joined. ```python import faster_os # Example usage with a list of path pairs paths_to_join = [ ('path/to/join', 'some path'), ('path/to/join', 'other path'), ('path/to/join', 'other path 2'), ('path/to/join', 'other path 3'), # ... potentially hundreds of thousands more entries ] # The actual multi_join function would process this list efficiently # faster_os.multi_join(paths_to_join) # Note: The '...' indicates that the list can be very long. ``` -------------------------------- ### Expand User Directory with Faster OS Source: https://github.com/ambeteco/faster-os/blob/main/README.md The expanduser function expands an initial path component referring to a user's home directory. It supports the '~' notation. ```python import faster_os faster_os.path.expanduser('~\Downloads\file.exe') # Expected output: 'C:\Users\Dsibe\Downloads\file.exe' faster_os.path.expanduser('~\Appdata') # Expected output: 'C:\Users\Dsibe\Appdata' ``` -------------------------------- ### Apply Splitext to Multiple Paths (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Applies the `splitext` function to each path in an iterable. It returns a list of tuples, where each tuple contains the root and extension for the corresponding input path. This is a batch operation for splitting extensions. ```python import faster_os.path paths_to_splitext = ['image.png', 'archive.tar.gz'] split_extensions = faster_os.path.multi_splitext(paths_to_splitext) print(split_extensions) ``` -------------------------------- ### Split Path and File Extension with Faster OS (Python) Source: https://context7.com/ambeteco/faster-os/llms.txt Demonstrates the functionality of `faster_os.path.splitext` for separating a filename from its extension. Covers cases with multiple dots, no extension, and Windows path formats, along with performance benchmarks. ```python import faster_os # Basic extension splitting root, ext = faster_os.path.splitext('document.txt') print(f"Root: {root}, Extension: {ext}") # Output: Root: document, Extension: .txt root, ext = faster_os.path.splitext('/home/user/photo.jpg') print(f"Root: {root}, Extension: {ext}") # Output: Root: /home/user/photo, Extension: .jpg # Multiple dots in filename root, ext = faster_os.path.splitext('archive.tar.gz') print(f"Root: {root}, Extension: {ext}") # Output: Root: archive.tar, Extension: .gz # No extension root, ext = faster_os.path.splitext('/path/to/file') print(f"Root: {root}, Extension: {ext}") # Output: Root: /path/to/file, Extension: # Windows paths root, ext = faster_os.path.splitext('C:\sample_photo.jpg') print(f"Root: {root}, Extension: {ext}") # Output: Root: C:\sample_photo, Extension: .jpg # Performance: 1059% faster than os.path.splitext # Process 1M paths in 8 seconds vs 1m 33s with standard os ``` -------------------------------- ### Faster OS vs OS Module: Exception Handling (TypeError) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Demonstrates that Faster OS and the standard 'os' module can raise similar TypeErrors for invalid argument types, such as None. ```python import os try: os.path.join('some path', None) except TypeError as e: print(f"os module TypeError: {e}") import faster_os try: faster_os.path.join('some path', None) except TypeError as e: print(f"Faster OS TypeError: {e}") ``` -------------------------------- ### Expand User Home Directory with faster_os.path.expanduser Source: https://context7.com/ambeteco/faster-os/llms.txt Expands the user home directory tilde ('~') to its full path. Supports both Unix-like and Windows home directory conventions. Handles specific user expansion and paths without a tilde. Provides significant performance benefits compared to os.path.expanduser. ```python import faster_os # Unix home directory expansion expanded = faster_os.path.expanduser('~/Documents/file.txt') print(expanded) # Output: /home/username/Documents/file.txt expanded = faster_os.path.expanduser('~/Desktop/projects') print(expanded) # Output: /home/username/Desktop/projects # Specific user home directory (Unix) expanded = faster_os.path.expanduser('~john/Documents') print(expanded) # Output: /home/john/Documents (if user 'john' exists) # Windows home directory expansion expanded = faster_os.path.expanduser('~\Downloads\file.exe') print(expanded) # Output: C:\Users\Username\Downloads\file.exe expanded = faster_os.path.expanduser('~\Desktop') print(expanded) # Output: C:\Users\Username\Desktop expanded = faster_os.path.expanduser('~\Appdata\Local') print(expanded) # Output: C:\Users\Username\Appdata\Local # No tilde - returns unchanged expanded = faster_os.path.expanduser('/absolute/path') print(expanded) # Output: /absolute/path ``` -------------------------------- ### Apply Relpath to Multiple Paths (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Applies the `relpath` function to each target path in an iterable, relative to a specified root path (or the current working directory if None). It returns a list of relative path strings. ```python import faster_os.path paths_to_relpath = ['/home/user/data/file.txt', '/home/user/config'] relative_paths = faster_os.path.multi_relpath(paths_to_relpath, root='/home/user') print(relative_paths) ``` -------------------------------- ### Apply Dirname to Multiple Paths (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Applies the `dirname` function to each path in an iterable. It returns a list of directory names extracted from the corresponding input paths. This allows for batch extraction of directory components. ```python import faster_os.path paths_to_dirname = ['/usr/bin/python', '/etc/config.conf'] dirnames = faster_os.path.multi_dirname(paths_to_dirname) print(dirnames) ``` -------------------------------- ### Apply Split to Multiple Paths (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Applies the `split` function to each path in an iterable (e.g., a list or tuple). It returns a list of tuples, where each tuple contains the directory and base name for the corresponding input path. This is a batch operation for `faster_os.path.split`. ```python import faster_os.path paths_to_split = ['a/b/c.txt', 'd/e.jpg'] splits = faster_os.path.multi_split(paths_to_split) print(splits) ``` -------------------------------- ### Apply Isabs to Multiple Paths (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Applies the `isabs` function to each path in an iterable. It returns a list of boolean values, where each value indicates whether the corresponding path is absolute. This provides a batch check for absolute paths. ```python import faster_os.path paths_to_check = ['/home/user', 'relative/path'] is_abs_list = faster_os.path.multi_isabs(paths_to_check) print(is_abs_list) ``` -------------------------------- ### Import Faster OS as os Module in Python Source: https://github.com/ambeteco/faster-os/blob/main/README.md This snippet demonstrates how to import the Faster OS library, aliasing it as 'os'. This allows for a drop-in replacement of Python's standard 'os' module, enabling the use of Faster OS's optimized functions for path manipulation. ```python # Use Faster OS to save hours of processing time! # The only thing you need to do is write... import faster_os as os ``` -------------------------------- ### Find Common Prefix for Multiple Paths using faster_os.path Source: https://github.com/ambeteco/faster-os/blob/main/README.md The `multi_commonprefix` function computes the common prefix for all paths within an iterable. It takes any iterable of paths and returns a list where each element is the common prefix for the corresponding path set. ```python faster_os.path.multi_commonprefix(paths) -> list ``` -------------------------------- ### Split UNC Network Path and Unix Paths Source: https://context7.com/ambeteco/faster-os/llms.txt Demonstrates the usage of `faster_os.path.splitdrive` to separate the drive (or UNC network path) from the rest of the path. It handles both Windows UNC paths and standard Unix-style paths, where the drive component is always empty. ```python import faster_os drive, path = faster_os.path.splitdrive('\\\\machine\\mountpoint\\directory\\file.txt') print(f"Drive: {drive}, Path: {path}") # Output: Drive: \\machine\mountpoint, Path: \directory\file.txt drive, path = faster_os.path.splitdrive('\\\\server\\share\\folder') print(f"Drive: {drive}, Path: {path}") # Output: Drive: \\server\share, Path: \folder # Unix systems (always returns empty drive) drive, path = faster_os.path.splitdrive('/home/user/file') print(f"Drive: {drive}, Path: {path}") # Output: Drive: , Path: /home/user/file ``` -------------------------------- ### Apply Splitdrive to Multiple Paths (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Applies the `splitdrive` function to each path in an iterable. It returns a list of tuples, where each tuple contains the drive and path components for the corresponding input path. Primarily useful on Windows. ```python import faster_os.path paths_to_splitdrive = ['C:\\Windows', 'D:\\Program Files'] splitdrives = faster_os.path.multi_splitdrive(paths_to_splitdrive) print(splitdrives) ``` -------------------------------- ### Normalize Path Separators and Resolve Dots Source: https://context7.com/ambeteco/faster-os/llms.txt Illustrates `faster_os.path.normpath` for normalizing path separators (converting `/` to `` on Windows where applicable) and resolving `.` (current directory) and `..` (parent directory) components. It handles various edge cases including multiple slashes and empty paths. ```python import faster_os # Unix path normalization normalized = faster_os.path.normpath('/home//user///documents//file.txt') print(normalized) # Output: /home/user/documents/file.txt normalized = faster_os.path.normpath('/home/user/./documents/../downloads/file') print(normalized) # Output: /home/user/downloads/file normalized = faster_os.path.normpath('///multiple///slashes///') print(normalized) # Output: /multiple/slashes # Windows path normalization normalized = faster_os.path.normpath('C:\\hello\\\world\\\') print(normalized) # Output: C:\hello\world normalized = faster_os.path.normpath('C:\Users\..\Windows\System32') print(normalized) # Output: C:\Windows\System32 normalized = faster_os.path.normpath('An invalid\\\path\\with many slashes\\\\\\') print(normalized) # Output: An invalid\path\with many slashes # Empty path handling normalized = faster_os.path.normpath('') print(normalized) # Output: . ``` -------------------------------- ### Expand User Home Path (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Expands the user's home directory reference ('~') within a path string to the actual home directory path. This function behaves like os.path.expanduser. ```python import faster_os.path expanded_path = faster_os.path.expanduser('~/Documents') print(f'Expanded path: {expanded_path}') ``` -------------------------------- ### Normalize Path with Faster OS Source: https://github.com/ambeteco/faster-os/blob/main/README.md The normpath function normalizes a path, collapsing redundant separators and up-level references. It handles Windows-style paths with multiple slashes. ```python import faster_os faster_os.path.normpath('C:\\hello\\\world\\\') # Expected output: 'C:\hello\world' faster_os.path.normpath('An invalid\\\path\\with many slashes\\\\\\') # Expected output: 'An invalid\path\with many slashes' ``` -------------------------------- ### Expand Home Directory for Multiple Paths with faster_os.path.multi_expanduser Source: https://context7.com/ambeteco/faster-os/llms.txt Expands the user's home directory (represented by '~') for a list of paths. This function is designed for batch processing, offering performance improvements when handling numerous paths that need home directory expansion. It takes a list of path strings and returns a new list with the expanded paths. ```python import faster_os user_paths = [ '~/Documents/file1.txt', '~/Downloads/file2.zip', '~/Desktop/project' ] expanded = faster_os.path.multi_expanduser(user_paths) print(expanded) ``` -------------------------------- ### Apply Normcase to Multiple Paths (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Applies the `normcase` function to each path in an iterable. It returns a list of normalized case path strings. This is useful for ensuring consistent path casing across different systems. ```python import faster_os.path paths_to_normcase = ['Path/To/File', 'path/to/FILE'] normcased_paths = faster_os.path.multi_normcase(paths_to_normcase) print(normcased_paths) ``` -------------------------------- ### Faster OS vs OS Module: Exception Handling (AttributeError) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Highlights a difference in exception handling where Faster OS might raise an AttributeError for invalid input (like None to normcase) while the 'os' module raises a TypeError. ```python import os try: os.path.normcase(None) except TypeError as e: print(f"os module TypeError: {e}") import faster_os try: faster_os.path.normcase(None) except AttributeError as e: print(f"Faster OS AttributeError: {e}") ``` -------------------------------- ### Identify Mount Points with faster_os.path.ismount Source: https://context7.com/ambeteco/faster-os/llms.txt Checks if a given path represents a filesystem mount point. Correctly identifies root directories on Unix-like systems and drive letters on Windows. Offers a dramatic speed improvement over os.path.ismount. ```python import faster_os # Unix mount point checking (only root '/' is mount) is_mount = faster_os.path.ismount('/') print(is_mount) # Output: True is_mount = faster_os.path.ismount('/home') print(is_mount) # Output: False is_mount = faster_os.path.ismount('/mnt/external') print(is_mount) # Output: False # Windows mount point checking (drive letters) is_mount = faster_os.path.ismount('C:') print(is_mount) # Output: True is_mount = faster_os.path.ismount('D:') print(is_mount) # Output: True (if D: drive exists) is_mount = faster_os.path.ismount('C:\Windows') print(is_mount) # Output: False is_mount = faster_os.path.ismount('C:\') print(is_mount) # Output: False (only drive letter without backslash) ``` -------------------------------- ### Apply abspath to Multiple Paths using faster_os.path Source: https://github.com/ambeteco/faster-os/blob/main/README.md The `multi_abspath` function applies the `abspath` operation to each path in a given iterable. It accepts lists, tuples, or other iterables and returns a new list containing the absolute paths. ```python faster_os.path.multi_abspath(paths) -> list ``` -------------------------------- ### Batch Path Operations (Python) Source: https://context7.com/ambeteco/faster-os/llms.txt Provides multi-function APIs for efficient batch processing of common path operations. These include extracting basenames, directory names, splitting paths, splitting extensions, joining path tuples, resolving absolute paths, normalizing paths, and checking for mount points. These functions offer significant performance gains over iterating standard library functions. ```python import faster_os # multi_basename - Extract basenames from multiple paths paths = [ '/home/user/document1.pdf', '/home/user/document2.pdf', '/home/user/image.jpg', '/var/log/system.log' ] basenames = faster_os.path.multi_basename(paths) print(basenames) # Output: ['document1.pdf', 'document2.pdf', 'image.jpg', 'system.log'] # Performance: 1599% faster for 4500 paths (0.042s vs 0.677s) # multi_dirname - Extract directories from multiple paths dirnames = faster_os.path.multi_dirname(paths) print(dirnames) # Output: ['/home/user', '/home/user', '/home/user', '/var/log'] # Performance: 1644% faster for 4500 paths (0.042s vs 0.689s) # multi_split - Split multiple paths splits = faster_os.path.multi_split(paths) print(splits) # Output: [('/home/user', 'document1.pdf'), ('/home/user', 'document2.pdf'), ...] # Performance: 1475% faster for 4500 paths (0.044s vs 0.653s) # multi_splitext - Split extensions from multiple paths exts = faster_os.path.multi_splitext(paths) print(exts) # Output: [('/home/user/document1', '.pdf'), ('/home/user/document2', '.pdf'), ...] # Performance: 1282% faster for 4500 paths (0.032s vs 0.408s) # multi_join - Join multiple path tuples join_pairs = [ ('/', 'home', 'user'), ('/', 'var', 'log'), ('/usr', 'local', 'bin'), ('/opt', 'applications') ] joined = faster_os.path.multi_join(join_pairs) print(joined) # Output: ['/home/user', '/var/log', '/usr/local/bin', '/opt/applications'] # Performance: 1418% faster for 1000 paths (0.020s vs 0.290s) # multi_abspath - Get absolute paths for multiple relative paths relative_paths = ['documents', 'downloads', '../Desktop', './projects'] absolute_paths = faster_os.path.multi_abspath(relative_paths) print(absolute_paths) # Performance: 195% faster for 4500 paths (1.31s vs 2.56s) # multi_normpath - Normalize multiple paths messy_paths = [ '/home//user///documents', 'C:\\Windows\\System32\\', '/var/./log/../cache' ] normalized = faster_os.path.multi_normpath(messy_paths) print(normalized) # Output: ['/home/user/documents', 'C:\Windows\System32', '/var/cache'] # Performance: 362% faster for 1300 paths (0.119s vs 0.432s) # multi_ismount - Check multiple paths for mount points mount_paths = ['/', '/home', 'C:', 'D:', 'C:\Windows'] mount_checks = faster_os.path.multi_ismount(mount_paths) print(mount_checks) # Output: [True, False, True, True, False] # Performance: 6853% faster for 4500 paths (1.29s vs 88.26s) - FASTEST IMPROVEMENT ``` -------------------------------- ### Normalize Path (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Normalizes a given path string. This function handles platform-specific path separators ('/' and '\') and resolves relative path components like '.' and '..'. It is a direct mirror of the standard os.path.normpath function. ```python import faster_os.path normalized_path = faster_os.path.normpath('some/path/../another/./dir') print(normalized_path) ``` -------------------------------- ### Apply Normpath to Multiple Paths (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Applies the `normpath` function to each path in an iterable. It returns a list of normalized path strings. This function provides a way to normalize multiple paths efficiently. ```python import faster_os.path paths_to_normalize = ['a/./b/../c', 'd/e'] normalized_paths = faster_os.path.multi_normpath(paths_to_normalize) print(normalized_paths) ``` -------------------------------- ### Compute Relative Path (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Calculates the relative path from a root directory to a target path. If no root is specified, it defaults to the current working directory. This function mirrors os.path.relpath. ```python import faster_os.path relative_path = faster_os.path.relpath('/usr/local/bin', '/usr') print(f'Relative path: {relative_path}') ``` -------------------------------- ### Split Drives from Multiple Windows Paths with faster_os.path.multi_splitdrive Source: https://context7.com/ambeteco/faster-os/llms.txt Splits the drive or UNC share name from the rest of the path for multiple Windows-style paths. This function efficiently handles a list of paths, returning a list of tuples where each tuple contains the drive/UNC component and the remaining path. It is optimized for batch processing. ```python import faster_os drive_paths = [ 'C:\\Windows\\System32', 'D:\\Data\\files', '\\\\server\\share\\folder' ] drives = faster_os.path.multi_splitdrive(drive_paths) print(drives) # Output: [('C:', '\\Windows\\System32'), ('D:', '\\Data\\files'), ('\\\\server\\share', '\\folder')] ``` -------------------------------- ### Benchmark Faster OS vs. Standard OS Path Operations Source: https://context7.com/ambeteco/faster-os/llms.txt This Python function benchmarks the performance of Faster OS path operations against the standard 'os.path' module. It measures the time taken to process a large list of file paths using both libraries, including Faster OS's single and multi-function capabilities. The results are printed to the console, showing the speed differences. ```python import time import os.path import faster_os def benchmark_faster_os_vs_os(): """Compare Faster OS performance against standard os module""" # Generate test data test_paths = [f'/data/files/batch{i//100}/file_{i}.txt' for i in range(10000)] # Standard os.path start = time.time() basenames_os = [os.path.basename(p) for p in test_paths] time_os = time.time() - start # Faster OS single functions start = time.time() basenames_faster = [faster_os.path.basename(p) for p in test_paths] time_faster_single = time.time() - start # Faster OS multi-function start = time.time() basenames_multi = faster_os.path.multi_basename(test_paths) time_faster_multi = time.time() - start print(f"Standard os.path: {time_os:.4f}s") print(f"Faster OS (single): {time_faster_single:.4f}s ({time_os/time_faster_single:.1f}x faster)") print(f"Faster OS (multi): {time_faster_multi:.4f}s ({time_os/time_faster_multi:.1f}x faster)") # Run the example if __name__ == '__main__': # Assuming process_large_file_collection is defined elsewhere and called # process_large_file_collection() benchmark_faster_os_vs_os() ``` -------------------------------- ### Extract Directory Name using faster_os.path.dirname Source: https://context7.com/ambeteco/faster-os/llms.txt Extracts the directory name from a given path. Works for both Unix-like and Windows path formats. Handles root directories and single-level paths correctly. Offers substantial performance gains over the standard os.path.dirname. ```python import faster_os # Unix directory name extraction dirname = faster_os.path.dirname('/var/log') print(dirname) # Output: /var dirname = faster_os.path.dirname('/single') print(dirname) # Output: / # Windows directory name extraction dirname = faster_os.path.dirname('C:\Users\User\Desktop\file.xlsx') print(dirname) # Output: C:\Users\User\Desktop dirname = faster_os.path.dirname('C:\HELLO WORLD\SOME PATH') print(dirname) # Output: C:\HELLO WORLD dirname = faster_os.path.dirname('C:\faster-os') print(dirname) # Output: C:\ # Root directory dirname = faster_os.path.dirname('/') print(dirname) # Output: (empty string) ``` -------------------------------- ### Extract Directory Path Component Source: https://context7.com/ambeteco/faster-os/llms.txt Demonstrates `faster_os.path.dirname` which extracts the directory component from a pathname. It effectively removes the final component (basename) and returns the path leading up to it, handling both Unix and Windows path conventions. ```python import faster_os # Unix directory name extraction dirname = faster_os.path.dirname('/home/user/documents/report.pdf') print(dirname) # Output: /home/user/documents dirname = faster_os.path.dirname('/var/log/system') print(dirname) # Output: /var/log ``` -------------------------------- ### Find Common Path Prefix String with Faster OS Source: https://github.com/ambeteco/faster-os/blob/main/README.md The commonprefix function returns the longest path prefix (string) that is a prefix of all paths in the list. This differs from commonpath as it operates on strings directly. ```python import faster_os faster_os.path.commonprefix([ 'C:\\', 'C:\\1\\123/123/123\\123', 'C:\\hello world\\some path', 'C:\\hello world\\some path\\' ]) # Expected output: 'C:\' ``` -------------------------------- ### Check if Path is a Mount Point (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Determines if a given path string represents a mount point in the file system hierarchy. This function is analogous to os.path.ismount. ```python import faster_os.path is_mounted = faster_os.path.ismount('/') print(f'Is mount point: {is_mounted}') ``` -------------------------------- ### Python: Cleanup Temporary Session Directories Source: https://context7.com/ambeteco/faster-os/llms.txt Removes temporary directories associated with completed sessions. It uses `faster_os.multi_removedirs` for efficient deletion of multiple directories and includes error handling for cases where some directories cannot be removed. ```python import faster_os def cleanup_temp_sessions(session_ids): """Clean up temporary directories for completed sessions""" temp_dirs = [ f'/tmp/app/sessions/{sid}/temp' for sid in session_ids ] try: faster_os.multi_removedirs(temp_dirs) print(f"Cleaned up {len(temp_dirs)} session directories") except OSError as e: print(f"Some directories could not be removed: {e}") # Usage cleanup_temp_sessions(['sess_001', 'sess_002', 'sess_003']) ``` -------------------------------- ### Check Absolute Path with faster_os.path.isabs Source: https://context7.com/ambeteco/faster-os/llms.txt Determines if a given path is absolute or relative. Supports both Unix-like and Windows path conventions. Significantly faster than the standard os.path.isabs function, processing paths at a much higher rate. ```python import faster_os # Unix absolute path checking is_absolute = faster_os.path.isabs('/home/user/documents') print(is_absolute) # Output: True is_absolute = faster_os.path.isabs('/var/log') print(is_absolute) # Output: True is_absolute = faster_os.path.isabs('relative/path') print(is_absolute) # Output: False is_absolute = faster_os.path.isabs('../parent/directory') print(is_absolute) # Output: False # Windows absolute path checking is_absolute = faster_os.path.isabs('C:\Users\User') print(is_absolute) # Output: True is_absolute = faster_os.path.isabs('D:\Data') print(is_absolute) # Output: True is_absolute = faster_os.path.isabs('~\user') print(is_absolute) # Output: False is_absolute = faster_os.path.isabs('relative\path') print(is_absolute) # Output: False is_absolute = faster_os.path.isabs('%USERPROFILE%\Documents') print(is_absolute) # Output: False ``` -------------------------------- ### Split Path into Drive and Path (Windows) (Python) Source: https://github.com/ambeteco/faster-os/blob/main/README.md Splits a path string into its drive component and the rest of the path. This function is primarily relevant for Windows operating systems. It functions similarly to os.path.splitdrive. ```python import faster_os.path drive, path_part = faster_os.path.splitdrive('C:\\Users\\Documents') print(f'Drive: {drive}, Path Part: {path_part}') ``` -------------------------------- ### Check if Path is Absolute with Faster OS Source: https://github.com/ambeteco/faster-os/blob/main/README.md The isabs function returns True if a pathname is absolute, False otherwise. It checks for drive letters on Windows and leading slashes on UNIX-like systems. ```python import faster_os faster_os.path.isabs('C:\Users\User') # Expected output: True faster_os.path.isabs('~\user') # Expected output: False faster_os.path.isabs('%USERPROFILE%\hi') # Expected output: False ```