{"id":4221,"library":"python-fsutil","title":"FSUtil: High-level File-System Operations","description":"python-fsutil provides a collection of high-level, convenient utilities for common file-system operations, simplifying tasks like reading, writing, copying, moving, and deleting files and directories. It aims to offer a more Pythonic and less verbose alternative to direct `os` and `shutil` module usage. The current version is 0.16.1, and the library maintains an active release cadence with minor updates every few months.","status":"active","version":"0.16.1","language":"en","source_language":"en","source_url":"https://github.com/fabiocaccamo/python-fsutil","tags":["file-system","filesystem","utility","fs","path","io"],"install":[{"cmd":"pip install python-fsutil","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"fsutil","correct":"import fsutil"}],"quickstart":{"code":"import fsutil\nimport os\nimport tempfile\nimport pathlib\n\n# Create a temporary directory for demonstration\nwith tempfile.TemporaryDirectory() as tmp_dir:\n    tmp_path = pathlib.Path(tmp_dir)\n\n    file_path = tmp_path / \"my_test_file.txt\"\n    content = \"Hello, fsutil!\\nThis is a test file.\"\n\n    # 1. Write content to a file (atomic operation for safety)\n    fsutil.write_file(file_path, content, encoding=\"utf-8\", atomic=True)\n    print(f\"File written to: {file_path}\")\n\n    # 2. Read content from the file\n    read_content = fsutil.read_file(file_path, encoding=\"utf-8\")\n    print(f\"Content read:\\n---\\n{read_content}---\")\n    assert read_content == content\n\n    # 3. Check if file exists\n    assert fsutil.file_exists(file_path)\n\n    # 4. Get file size\n    size = fsutil.get_file_size(file_path)\n    print(f\"File size: {size} bytes\")\n\n    # 5. Create a nested directory\n    new_dir_path = tmp_path / \"parent_dir\" / \"child_dir\"\n    fsutil.create_dir(new_dir_path)\n    print(f\"Directory created: {new_dir_path}\")\n    assert fsutil.dir_exists(new_dir_path)\n\n    # 6. Remove the file\n    fsutil.remove_file(file_path)\n    assert not fsutil.file_exists(file_path)\n    print(f\"File removed: {file_path}\")\n\n    # 7. Remove the directory (recursively)\n    fsutil.remove_dir(tmp_path / \"parent_dir\")\n    assert not fsutil.dir_exists(tmp_path / \"parent_dir\")\n    print(f\"Directory removed: {tmp_path / 'parent_dir'}\")\n\nprint(\"fsutil quickstart completed successfully.\")","lang":"python","description":"This quickstart demonstrates basic file and directory operations: creating a temporary file and directory, writing and reading file content, checking existence, getting file size, and finally cleaning up both the file and the created directory."},"warnings":[{"fix":"Upgrade to `python-fsutil` version 0.16.0 or newer to ensure robust and cross-platform atomic file operations with improved permission handling and Windows compatibility.","message":"Atomic file operations (fsutil.write_file with `atomic=True`) had known issues with preserving file permissions and exhibited inconsistent behavior on Windows in versions prior to 0.16.0. This could lead to incorrect permissions or data loss on specific platforms, or race conditions if not handled carefully.","severity":"gotcha","affected_versions":"< 0.16.0"},{"fix":"Update to `python-fsutil` version 0.16.1 or newer for corrected and consistent path handling in search operations, especially when using relative paths or expecting OS-specific path separators.","message":"Search methods like `fsutil.search_files` and `fsutil.search_dirs` exhibited incorrect behavior when dealing with relative paths and sometimes failed to normalize paths using OS-specific separators in versions prior to 0.16.1. This could lead to unexpected results or missed files/directories in search operations.","severity":"gotcha","affected_versions":"< 0.16.1"},{"fix":"Upgrade to `python-fsutil` version 0.14.0 or newer to ensure correct behavior of `join_filename` with empty name components.","message":"The `fsutil.join_filename` method could return incorrect or unexpected values when the `basename` or `extension` arguments were empty in versions prior to 0.14.0. This might affect applications relying on precise filename construction from components.","severity":"gotcha","affected_versions":"< 0.14.0"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}