Path Parser
Overview
The Path Parser provides comprehensive path resolution and management for FreeWorld OS. It handles virtual drives, UNC paths, path normalization, and drive management, providing Windows-compatible path handling.
Features
- Virtual Drive Management: Register and manage virtual drives (C:, D:, etc.)
- UNC Path Support: Parse and handle UNC paths (
\\server\share\path) - Path Normalization: Resolve
..and.components - Path Resolution: Convert relative paths to absolute paths
- Path Component Splitting: Extract directory, filename, extension
- Drive Information: Query drive details and existence
- Path Validation: Check if paths exist, are directories, or files
Virtual Drives
The Path Parser supports Windows-style virtual drives:
C:- Root filesystem (maps to/)D:- Secondary drive (maps to/mnt/d)- Additional drives can be registered dynamically
Drive Management Functions
registerDrive(letter, path)- Register a virtual driveunregisterDrive(letter)- Unregister a virtual drivegetDrivePath(letter)- Get path for a drive lettergetAllDrives()- Get all registered drivesgetDriveInfo(letter)- Get detailed drive information
Path Operations
Path Parsing
parsePath(path, currentDir)- Parse and normalize a pathnormalizePath(path)- Normalize path (resolve..and.)joinPaths(...paths)- Join multiple path componentsresolvePath(processId, path)- Resolve path using process's current directoryresolveFullPath(path)- Resolve all symbolic links and relative components
Path Component Extraction
getDirectoryName(path)- Get directory portion of pathgetFileName(path)- Get filename from pathgetExtension(path)- Get file extensionsplitPath(path)- Split path into all components (root, dir, base, name, ext)
Path Validation
isAbsolutePath(path)- Check if path is absoluteisUNCPath(path)- Check if path is UNCpathExists(path)- Check if path existsisDirectory(path)- Check if path is a directoryisFile(path)- Check if path is a filegetRootPath(path)- Get root path (drive or UNC server/share)
UNC Path Support
The Path Parser supports UNC (Universal Naming Convention) paths for network shares:
// Parse UNC path
const unc = pathParser.parseUNCPath('\\\\server\\share\\path\\file.txt');
// Returns: { server: 'server', share: 'share', path: 'path\\file.txt' }
UNC paths are automatically detected and parsed separately from local paths.
Current Directory Management
The Path Parser tracks current directory per process:
setCurrentDirectory(processId, path)- Set current directory for processgetCurrentDirectory(processId)- Get current directory for process
Usage Example
const PathParser = require('./system/path');
const pathParser = new PathParser();
// Register a new drive
pathParser.registerDrive('E:', '/mnt/e');
// Parse a path with virtual drive
const resolved = pathParser.parsePath('C:\\Users\\test\\file.txt');
// Returns: '/Users/test/file.txt'
// Parse UNC path
const unc = pathParser.parseUNCPath('\\\\server\\share\\file.txt');
// Returns: { server: 'server', share: 'share', path: 'file.txt' }
// Get path components
const parts = pathParser.splitPath('/usr/bin/node');
// Returns: { root: '/', dir: '/usr/bin', base: 'node', name: 'node', ext: '' }
// Check if path exists
if (pathParser.pathExists('/usr/bin/node')) {
console.log('Node.js found');
}
Integration
The Path Parser integrates with:
- Object Manager: Used for file path resolution
- Shell: Used for command path resolution
- ShellExecute: Used for executable path resolution
- Filesystem: Used for all filesystem operations