Skip to main content

A dead simple Python 3.x file helper

Project description

libfile

A dead simple file helper for Python 3.x.

pip install libfile

Tutorial Contributing License

Tutorial

libfile provides basic utilities for file interaction and management.

Setup

Make sure you import the File class from libfile and instanciate it with a path.

from libfile import File


test_file = File("test_file.txt")

Note that the File class gives dates as a datetime. If you wish to get the raw dates (as a unix timestamp), instanciate the class with dates_as_datetime set to False.

Properties

.path = str -> The given path

.abs_path = str -> The absolute path of .path

.readable = bool -> Whether or not the file is readable
.data = str -> The contents of the file
.lines = list -> A list of the lines in the file
.line_count = int -> The length of .lines
.is_empty = bool -> Whether or not the file is empty

.size_in_bytes = int -> The size of the file, in bytes
.size = str -> The size of the file, formatted

.created = datetime/int -> When the file was created
.last_modified = datetime/int -> When the file was last modified
.last_accessed = datetime/int -> When the file was last accessed

.full_name = str -> Full name of the file, excluding its path
.name = str -> Name of the file, excluding its path and extension
.extension = str -> File extension, excluding its path and name

.dir_path = str -> Path of the file's directory
.dir_name = str -> Name of the file's directory

File Manipulation

Renaming

Rename the file to new_name.

test_file.rename(new_name="foo_bar.txt")

Copying

Followable

Copy the file to location with an optional new_name.

test_file.copy(location="..", follow=True)

Duplicating

Followable

Duplicate the file amount times with an optional splitter.

test_file.duplicate(amount=3, splitter=" ")

# <directory> |
#     - test_file.txt
#     - test_file 0.txt
#     - test_file 1.txt
#     - test_file 2.txt

Moving

Move the file to location. This method is followed automatically.

test_file.move("../../secret_stuff")

Deleting

Delete the file.

test_file.delete()

# Poof!

Finding

Find all lines from the given query.

test_file.find("testing")

# ["Stop testing me!"]

Empty

Empty the file.

test_file.empty()

# NNNOOOoooooooₒₒₒₒₒₒₒ...

Note

There are still a lot of things to be implemented. Feel free to contribute anything you think should be added!

Following

Following is a very simple method in the File class which calls for os to change the directory to the given location.

It is available in most methods as an argument, and can be disabled.

Contributing

We welcome all contributions. Before submitting a pull request, make sure your editor supports pylint for Python linting, autopep8 for Python formatting, and editorconfig for general file quality assurance.

License

MIT

Project details


Release history Release notifications

Download files

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

Files for libfile, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size libfile-0.0.1-py3-none-any.whl (5.4 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size libfile-0.0.1.tar.gz (4.5 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page