Skip to main content

Simple CRUD operations for file handling in Python

Project description

File Crud

Simple CRUD operations for files and directories in Python.

Description

file-crud is a lightweight Python package that provides basic Create, Read, Update, and Delete (CRUD) functions for handling files and directories easily. It includes safe operations with error handling and supports nested directories. Perfect for beginners or simple file management tasks.

The package normalizes file and directory paths across different operating systems (Windows, Linux, macOS), ensuring consistent behavior regardless of how paths are written or used.

Features

Create a new file with content.

Read the content of a file.

Update (append) content to an existing file.

Delete a file safely with error handling.

Create and delete directories, including nested folders.

Optional recursive deletion: remove directories even if they contain files/subfolders.

Copy and move files with optional overwrite protection.

Copy and move directories recursively with optional overwrite.

Cross-platform path normalization to handle differences between operating systems.

Installation

pip install file-crud

Usage

import file_crud as fc #more easy to use

#Create a file

fc.create_file('example.txt', 'Hello, world!') # If you don’t want content, pass None

#Read the file

content = fc.read_file('example.txt')

#Update the file

fc.update_file('example.txt', '\nThis is an added line.') # If no content to add, pass None

## Delete the file

fc.delete_file('example.txt')

## Create a directory (nested paths allowed)

fc.create_directory('my_folder/subfolder')

## Delete a directory (only if empty)

fc.delete_directory('my_folder/subfolder')

## Delete a directory recursively (removes all contents)

fc.delete_directory('my_folder', recursive=True)

## Copy a file (won't overwrite by default)

fc.copy_file('source.txt', 'destination.txt')

## Move a file (won't overwrite by default)

fc.move_file('old_location.txt', 'new_location.txt')

## Copy a directory recursively (won't overwrite by default)

fc.copy_directory('source_folder', 'destination_folder')

## Move a directory recursively (won't overwrite by default)

fc.move_directory('old_folder', 'new_folder')

Notes on recursive deletion and overwrite

delete_directory with recursive=True removes the entire directory and all its contents — use with caution.

Copy and move functions accept an overwrite parameter (default False) to control whether existing files/directories get overwritten.

Path Normalization

All functions internally normalize file and directory paths to ensure compatibility across Windows, Linux, and macOS. This means you can use paths with ~, relative paths, or different slash styles, and they will be handled correctly.

Logs

0.2.5

Description Bugs Fixed.

0.2.4

Description new areas.

0.2.0

Can copy and move files and directories. New Path Normalization

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

file_crud-0.2.5.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

file_crud-0.2.5-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file file_crud-0.2.5.tar.gz.

File metadata

  • Download URL: file_crud-0.2.5.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for file_crud-0.2.5.tar.gz
Algorithm Hash digest
SHA256 b138b10e47623f6eafa275b173b368c69ed4126bbabd13277c706a28e0ae447c
MD5 8cf19756a509f1496257aa822c16a6b3
BLAKE2b-256 31fce5b2ec6cf5519c1853657dfe3f966a43bea584940ccd6d6cbe419db5a8c5

See more details on using hashes here.

File details

Details for the file file_crud-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: file_crud-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for file_crud-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 884f20ee09b3957c39abfca95e198ddbe8619a7735e0fb5d2f6f3661a5aa0953
MD5 bc891e5e3ff4c90898d7747c7155c30a
BLAKE2b-256 06570cf4c57bd9f59b2ce470098e8bc23afccfe01ae95b0bdacc86ed7e2cfef2

See more details on using hashes here.

Supported by

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