Skip to main content

A simple folder management library

Project description

Folder Manager

Folder Manager is a simple Python package for managing folders and files. It provides methods to create folders, list files, count files, create files, delete files, move files, and copy files with optional verbose output.

Installation

You can install the package via pip:

pip install folder_manager

Usage

Importing the Folder class

First, import the Folder class from the folder_manager package:

from folder_manager import Folder

Creating a Folder Instance

Create an instance of the Folder class by specifying the folder path and an optional verbose flag:

folder = Folder('C:\\path\\to\\folder', verbose=True)

Creating a Folder

To create the specified folder, use the create_folder method:

if folder.create_folder():
    print("Folder created successfully.")
else:
    print("Failed to create folder.")

Checking if a Folder Exists

To check if the folder exists, use the folder_exists method:

if folder.folder_exists():
    print("Folder exists.")
else:
    print("Folder does not exist.")

Listing Files in a Folder

To list all files in the folder, use the list_files method:

files = folder.list_files()
print(f"Files: {files}")

Counting Files in a Folder

To count the number of files in the folder, use the count_files method:

file_count = folder.count_files()
print(f"Number of files: {file_count}")

Creating a File

To create a file in the folder, use the create_file method:

if folder.create_file('example.txt', 'Hello, world!'):
    print("File created successfully.")
else:
    print("Failed to create file.")

Deleting a File

To delete a file from the folder, use the delete_file method:

if folder.delete_file('example.txt'):
    print("File deleted successfully.")
else:
    print("Failed to delete file.")

Moving a File

To move a file within the file system, use the move_file method:

if folder.move_file('C:\\path\\to\\folder\\example.txt', 'C:\\new\\path\\example.txt'):
    print("File moved successfully.")
else:
    print("Failed to move file.")

Copying a File

To copy a file within the file system, use the copy_file method:

if folder.copy_file('C:\\path\\to\\folder\\example.txt', 'C:\\new\\path\\example.txt'):
    print("File copied successfully.")
else:
    print("Failed to copy file.")

Deleting a Folder

To delete the folder and all its contents, use the delete_folder method:

if folder.delete_folder():
    print("Folder deleted successfully.")
else:
    print("Failed to delete folder.")

CLI Usage

You can also use the Folder Manager via the command line:

# Create a folder
folder-manager create_folder "C:\path\to\folder"

# Check if a folder exists
folder-manager folder_exists "C:\path\to\folder"

# List files in a folder
folder-manager list_files "C:\path\to\folder"

# Count files in a folder
folder-manager count_files "C:\path\to\folder"

# Create a file in a folder
folder-manager create_file "C:\path\to\folder" --file_name example.txt --content "Hello, world!"

# Delete a file from a folder
folder-manager delete_file "C:\path\to\folder" --file_name example.txt

# Move a file
folder-manager move_file "C:\path\to\folder" --file_name example.txt --dest "C:\new\path\example.txt"

# Copy a file
folder-manager copy_file "C:\path\to\folder" --file_name example.txt --dest "C:\new\path\example.txt"

# Delete a folder
folder-manager delete_folder "C:\path\to\folder"

Example Script

Here is a complete example script demonstrating how to use the Folder class:

from folder_manager import Folder

def main():
    # Create an instance of Folder with verbose=True to enable printing
    folder = Folder('C:\\path\\to\\folder', verbose=True)

    # Create a folder
    if folder.create_folder():
        print("Folder created successfully.")
    else:
        print("Failed to create folder.")

    # Check if the folder exists
    if folder.folder_exists():
        print("Folder exists.")
    else:
        print("Folder does not exist.")

    # List files in the folder
    files = folder.list_files()
    print(f"Files: {files}")

    # Count files in the folder
    file_count = folder.count_files()
    print(f"Number of files: {file_count}")

    # Create a new file in the folder
    if folder.create_file('example.txt', 'Hello, world!'):
        print("File created successfully.")
    else:
        print("Failed to create file.")

    # List files again to see the new file
    files = folder.list_files()
    print(f"Files after creation: {files}")

    # Delete the file
    if folder.delete_file('example.txt'):
        print("File deleted successfully.")
    else:
        print("Failed to delete file.")

    # List files again to confirm deletion
    files = folder.list_files()
    print(f"Files after deletion: {files}")

    # Delete the folder and its contents
    if folder.delete_folder():
        print("Folder deleted successfully.")
    else:
        print("Failed to delete folder.")

    # Create another instance of Folder with verbose=False to disable printing
    folder_silent = Folder('C:\\path\\to\\folder', verbose=False)

    # Create a folder silently (no print output)
    if folder_silent.create_folder():
        print("Folder created successfully (silent).")
    else:
        print("Failed to create folder (silent).")

    # Check if the folder exists silently (no print output)
    if folder_silent.folder_exists():
        print("Folder exists (silent).")
    else:
        print("Folder does not exist (silent).")

if __name__ == "__main__":
    main()

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

Author

Javer Valino

Acknowledgements

  • Python's os, shutil and argparse libraries

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

folder_manager-0.1.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

folder_manager-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file folder_manager-0.1.0.tar.gz.

File metadata

  • Download URL: folder_manager-0.1.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for folder_manager-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3383cbcd78d434d37a2e47ac752cefd37c44c8947774e81f5535d77e67153245
MD5 0ee3c5767b103d0349ca9679b4067dd5
BLAKE2b-256 b38ea386b92b9dff8c00c75b0b35a4ca2f0c77cd3c2069a16d7367d18998e9d9

See more details on using hashes here.

File details

Details for the file folder_manager-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for folder_manager-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2cd186bd653dd8dda2b0936732a9d036b2a2b83ceb17883e131c907b2f1c42bb
MD5 48e14c0b369e33791db37533381d726e
BLAKE2b-256 1a5e945f3b8662548c36b80222d394ec55f786a75632c277a5c51970af7b8762

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page