Skip to main content

Helper module for locating and deleting files and folders.

Project description

Fileutility

File utility is a helper module for locating files on the local file system. It provides functionality to find files based on recursion, min-mtime, max-mtime, file suffix and timestamped filenames with regexp.

At a Glance

Installation using pip:

pip install fileutility

Example usages of fileutility:

Locate all .txt files

import fileutility

found_files = fileutility.find_files(path='/', file_suffix='.txt')

Locate all files last modified between 2017-11-30 and 2018-11-30

import fileutility
from datetime import datetime

found_files = fileutility.find_files(
    path='/', 
    minimum_file_age=datetime(2018,11,30), 
    maximum_file_age=datetime(2017,11,30)
)

Locate all .txt files with dates in filename from 2017-11-30 to 2018-11-30

import fileutility
from datetime import datetime

found_files = fileutility.find_datetime_named_files(
    path='/'
    minimum_file_age=datetime(2018,11,30),
    maximum_file_age=datetime(2017,11,30),
    file_suffix='.txt'
)

Locate all files in the local folder only

import fileutility

found_files = fileutility.find_files(
    path='/',
    recursion_depth=0
)

Delete all files in a folder and remove folder

import fileutility

found_files = fileutility.find_files(
    path='/tmp/test/'
)

delete_files(
    files=found_files,
    directory_delete=True
)

Requirements

  • Python2.7

Warning. Package has only been tested on Linux and Mac.

Supported date in filename filters from out of the box:

  • yyyy(-._)mm(-._)dd
  • yy(-._)Mon(-._)dd
  • yyyy(-._)Mon(-._)dd
  • yy(-._)mon(-._)dd
  • yyyy(-._)mon(-._)dd
  • yyyy(-._)Mon(-._)dd
  • yy(-._)Mon(-._)dd
  • yyyy(-._)mon(-._)dd
  • yy(-._)mon(-._)dd
  • yyyy-mm-ddTHH:MM:SS

If none of the above regexps provide the filter or isn't specific enough you need to apply you can always write your own:

import fileutility

found_files = fileutility.find_datetime_named_files(
    path='/'
    minimum_file_age=datetime(2018,11,30),
    maximum_file_age=datetime(2017,11,30),
    file_suffix='.txt',
    regexp=r'^myfilename-[a-z]{4,10}([0-9]{2})\@([a-z]{3})\@([0-9]{2})'
)

Unit tests status

test_find_all (__main__.TestFindDatetimeFiles) ... ok
test_find_all_suffix (__main__.TestFindDatetimeFiles) ... ok
test_find_older (__main__.TestFindDatetimeFiles) ... ok
test_find_older_younger (__main__.TestFindDatetimeFiles) ... ok
test_find_older_younger_suffix (__main__.TestFindDatetimeFiles) ... ok
test_find_regexp (__main__.TestFindDatetimeFiles) ... ok
test_find_regexp_suffix (__main__.TestFindDatetimeFiles) ... ok
test_find_regexp_suffix_no_recursion (__main__.TestFindDatetimeFiles) ... ok
test_find_root (__main__.TestFindDatetimeFiles) ... ok
test_find_subdir (__main__.TestFindDatetimeFiles) ... ok
test_find_younger (__main__.TestFindDatetimeFiles) ... ok
test_delete_files (__main__.TestFindFiles) ... ok
test_delete_files_and_directory (__main__.TestFindFiles) ... ok
test_find_all (__main__.TestFindFiles) ... ok
test_find_all_suffix (__main__.TestFindFiles) ... ok
test_find_older (__main__.TestFindFiles) ... ok
test_find_older_younger (__main__.TestFindFiles) ... ok
test_find_older_younger_suffix (__main__.TestFindFiles) ... ok
test_find_root (__main__.TestFindFiles) ... ok
test_find_subdir (__main__.TestFindFiles) ... ok
test_find_younger (__main__.TestFindFiles) ... ok

----------------------------------------------------------------------
Ran 21 tests in 0.075s

OK

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

fileutility-0.6.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

fileutility-0.6-py2-none-any.whl (6.6 kB view details)

Uploaded Python 2

File details

Details for the file fileutility-0.6.tar.gz.

File metadata

  • Download URL: fileutility-0.6.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.14.2 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for fileutility-0.6.tar.gz
Algorithm Hash digest
SHA256 ec3059bb095be2dded43757e531c278bff057b48704a6247f5fab67ab57c7e2a
MD5 d6ada74f8f2fa39b9492f8746f97c5f9
BLAKE2b-256 28e15a624527e3f1a961edc150724b8aba6e367bf7b07c8f24c48811308068ee

See more details on using hashes here.

File details

Details for the file fileutility-0.6-py2-none-any.whl.

File metadata

  • Download URL: fileutility-0.6-py2-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.14.2 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for fileutility-0.6-py2-none-any.whl
Algorithm Hash digest
SHA256 13f0a46b74f88866365c43b10e5b380e6e3b7fe12f772e1446106bcfc19221aa
MD5 d7dcf78baeb160384582d6a1f35db674
BLAKE2b-256 3ff5b958b0f06fcf2ca5c5da56586e5d01c72c9a6c6b695ef2fde81c0c796e13

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