Wrapper Module

The Wrapper module is a comprehensive toolkit that provides a set of utility functions specifically designed to facilitate file and directory operations. These operations may include creating, reading, updating, and deleting files or directories. It is an integral part of the FileSystemPro library, designed to provide detailed information about files and directories, including functions for retrieving metadata and checking file extensions.

Features

  • Metadata Retrieval: Gathers comprehensive metadata about a file or directory path.

  • Extension Check: Determines whether a file has an extension.

# Wrapper

## Overview Wrapper is an integral part of the FileSystemPro library, designed to provide detailed information about files and directories. It includes functions for retrieving metadata and checking file extensions.

## Features - Metadata Retrieval: Gathers comprehensive metadata about a file or directory path. - Extension Check: Determines whether a file has an extension.

## Detailed Functionality The module’s functions are crafted to offer detailed insights into the file system and to perform common file operations with ease.

### Metadata Retrieval (get_object) The get_object function is the centerpiece of this module. It returns a dictionary containing various properties of the given path, such as absolute path, access time, creation time, directory name, existence, file type, link status, extension, modification time, file name, size, and more.

### Extension Check (has_extension) The has_extension function checks if a given file path has an extension, which is useful for file type validation or processing logic that depends on file types.

## Usage To use the functions provided by this module, import the module and call the desired function with the appropriate parameters:

`python from filesystem import wrapper as wra `

filesystem.wrapper.get_object(path)[source]

# wrapper.get_object(path)

### Overview Retrieves various details about the file or directory at the specified path. These details include the absolute path, access date, creation date, directory name, existence, type (file, directory, or link), extension, modification date, name, name without extension, and size.

### Parameters: path (str): The file or directory path to retrieve details of.

### Returns: dict: A dictionary with the following keys: - “abspath”: The absolute path. - “access”: The last access time, or -1 if an error occurs. - “created”: The creation time, or -1 if an error occurs. - “dirname”: The directory name. - “exists”: A boolean indicating whether the path exists. - “is_dir”: A boolean indicating whether the path is a directory. - “is_file”: A boolean indicating whether the path is a file. - “is_link”: A boolean indicating whether the path is a symbolic link. - “extension”: The file extension, or an empty string if the path is not a file. - “ext”: The file extension, or an empty string if the path is not a file. Kept for version support. - “modified”: The last modification time, or -1 if an error occurs. - “name”: The base name of the path. - “name_without_extension”: The base name of the path without the extension. - “size”: The size of the file, or -1 if an error occurs.

### Raises: - FileNotFoundError: If the file or directory does not exist. - PermissionError: If the permission is denied.

### Examples: - Retrieves details of a file.

`python get_object("/path/to/file") ` - Retrieves details of a directory.

`python get_object("/path/to/directory") `

filesystem.wrapper.has_extension(file_path)[source]

# wrapper.has_extension(file_path)

### Overview Checks if the given file path has an extension. This function can return True or False based on the string, even if the file or directory does not exist.

### Parameters: file_path (str): The file path to check for an extension.

### Returns: bool: True if the file path has an extension, False otherwise.

### Examples: - Checks if the file path has an extension.

`python has_extension("/path/to/file.txt") ` This will return True because the file has an extension (.txt).

  • Checks if the file path has an extension.

`python has_extension("/path/to/file") ` This will return False because the file does not have an extension.

Methods

The Wrapper module in FileSystemPro brings a comprehensive set of methods that streamline and enhance file and directory management.

from filesystem import wrapper as wra

Method

Description

wrapper.get_object(path)

This function takes a file or directory path as input and returns a dictionary containing various attributes of the file or directory. These attributes include the time of last modification, creation time, last access time, name, size, absolute path, parent directory, whether it’s a directory or file or link, whether it exists, and its extension (if it’s a file).

wrapper.has_extension(file_path)

Checks if the given file path has an extension. This function can return True or False based on the string, even if the file or directory does not exist.

Examples

Has Extension

The following example checks if the given file path has an extension using Wrapper.

from filesystem import wrapper as wra

bool_extension = wra.has_extension("/path/to/file.txt")
print(bool_extension)

Output:

True

This will return True because the file has an extension (.txt).

from filesystem import wrapper as wra

bool_extension = wra.has_extension("/path/to/file")
print(bool_extension)

Output:

False

This will return False because the file does not have an extension.