Implementation:Microsoft Playwright FileUtils
Appearance
Overview
FileUtils provides file system utility functions for common operations like directory creation, file removal, path sanitization, and zip file creation used throughout Playwright's server code.
Description
This module exports a collection of file system helpers:
existsAsync-- async file existence checkmkdirIfNeeded-- creates parent directories recursively for a file pathremoveFolders-- recursively removes multiple directories in parallelcanAccessFile-- synchronous file accessibility checkcopyFileAndMakeWritable-- copies a file and sets writable permissionssanitizeForFilePath-- removes unsafe characters from path componentstoPosixPath-- converts platform-specific paths to POSIX formataddZipFile-- adds files to zip archives using yazl
Usage
Used throughout the codebase for file operations, temporary directory management, and artifact storage.
Code Reference
Source Location
packages/playwright-core/src/server/utils/fileUtils.ts (205 lines)
Function Signatures
export const existsAsync: (path: string) => Promise<boolean>;
export async function mkdirIfNeeded(filePath: string): Promise<void>;
export async function removeFolders(dirs: string[]): Promise<(Error | undefined)[]>;
export function canAccessFile(file: string): boolean;
export async function copyFileAndMakeWritable(from: string, to: string): Promise<void>;
export function sanitizeForFilePath(s: string): string;
export function toPosixPath(aPath: string): string;
Import
import { mkdirIfNeeded, removeFolders, canAccessFile, sanitizeForFilePath } from './server/utils/fileUtils';
I/O Contract
Key Behaviors
mkdirIfNeededsilently ignores errors (e.g., root directory on Windows)removeFoldersusesmaxRetries: 10for resilience on WindowssanitizeForFilePathreplaces control characters and special characters with hyphens
Related Pages
- Microsoft_Playwright_LocalUtils -- Uses file utilities for trace operations
- Microsoft_Playwright_ProcessLauncher -- Uses removeFolders for cleanup
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment