Skip to content

Simplified file path management for Python developers

License

Notifications You must be signed in to change notification settings

aboutmydreams/way3

Repository files navigation

Way3: A Python Module for File Operations

Auto CI and Build Tools Auto Publish to PyPI and GitHub Release label label Release Version Visits License Stars Forks Downloads Contributors

Way3 is a Python module for performing file operations such as creating, appending to, and deleting files. It provides a convenient and easy-to-use interface for performing file operations.

Installation

To install Way3, you can use pip:

pip install way3

or use poetry:

poetry add way3 

Usage

Here are the functions provided by Way3:

create_file(file_name: str, content: str, file_path: Union[str, os.PathLike] = ".", force_rewrite: bool = True) -> tuple[bool, str]

Creates a new file with the given file name and content. If the file already exists and force_rewrite is set to True, the file will be overwritten.

Example:

import way3

result = way3.create_file("test.txt", "test")
print(result[1])  # prints the absolute path of the created file

add_to_file_end(file_name: str, content: str, file_path: Union[str, os.PathLike] = ".", create_if_not_exist: bool = True) -> tuple[bool, str]

Appends the given content to the end of the file with the given file name. If the file does not exist and create_if_not_exist is set to True, a new file will be created.

Example:

import way3

result = way3.add_to_file_end("test.txt", "test")
print(result[1])  # prints the absolute path of the file

delete_file(file_name: str, file_path: Union[str, os.PathLike] = ".") -> tuple[bool, str]

Deletes the file with the given file name.

Example:

import way3

result = way3.delete_file("test.txt")
print(result[1])  # prints the absolute path of the deleted file

get_current_dir(instance=file) -> str

Returns the current working directory.

Example:

import way3

result = way3.get_current_dir()
print(result)  # prints the current working directory

create_directory(directory_name: str, directory_path: Union[str, os.PathLike] = ".") -> str

Creates a new directory with the given name.

Example:

import way3

result = way3.create_directory("my_directory")
print(result)  # prints the absolute path of the created directory

rename_directory(original_name: str, new_name: str) -> str

Renames a directory with a new name.

Example:

import way3

result = way3.rename_directory("old_directory", "new_directory")
print(result)  # prints the absolute path of the renamed directory

delete_directory(directory_name: str, directory_path: Union[str, os.PathLike] = ".") -> str

Deletes a directory and all its contents.

Example:

import way3

result = way3.delete_directory("my_directory")
print(result)  # prints the absolute path of the deleted directory

Let me know if you need any further modifications!

Testing

To run the tests, you can use the following command:

python3 -m unittest discover -s tests

License

Way3 is released under the MIT License. See LICENSE for details.

I hope you find Way3 useful! If you have any questions or feedback, please open an issue or pull request.

About

Simplified file path management for Python developers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages