Skip to content

Utility functions for reading directory contents and refactoring folder structure

License

Notifications You must be signed in to change notification settings

sfneal/dirutility

Repository files navigation

Directory Utilities

Build Status PyPi version PyPi Python support PyPi downloads per month PyPi license StyleCI Scrutinizer Code Quality

dirutility is a Python package for generating an inventory of files within a directory tree.

Often we encounter directories with vast file structures too large to sort through by manually. Directory Utilities allows users to create inventories of files and manipulated data structures._

How it works

Directory Utilities is built using almost entirely builtin Python libraries making it extremely lightweight. The walk module performs 'inventory' tasks that return information on file and folder contents of a root directory. The move module performs 'structure' tasks that reorganize the data structures within a directory based on a variety of parameters.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

Upgrade to the latest version of pip

pip install --upgrade pip

Installing

Create a virtual development environment and install the latest version of dirutility from PyPi or github

PyPi distribution

pip install dirutility

GitHub distribution

pip install git+git://github.com/sfneal/dirutility.git

or

pip install git+https://github.com/sfneal/dirutility.git

Example Usage

Outlined below are basic uses of the four main classes of the directory utility python package.

  • DirPaths - Retrieve a list of paths within a root directory
  • DirTree - Retrive a nested dictionary representing a roots file structure
  • FlattenTree - Flattens the contents of a root directory by moviing all sub-folders and files to root
  • CreateTree - Create organized file structure based on indexing of files within root

DirPaths class

This class generates a list of either files and or folders within a root directory. The walk method generates a directory list of files by walking the file tree top down or bottom up. The files and folders method generate a list of files or folders in the top level of the tree.

Generate list of all file paths within a directory.

Generate file paths list with filters specifying what files to include (not limited to file types, can be any string).

Generate file paths list and exclude particular files.

Generate file paths list with concatenated full paths.

# Root directory
root = '/Volumes/Storage/test'
dirs = DirPaths(root, to_include=['.psd', '.png'], to_exclude=['.dwg'])

Built With

  • looptools - Logging output, timing processes and counting iterations.
  • tqdm - A fast, extensible progress bar for Python

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

License

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

About

Utility functions for reading directory contents and refactoring folder structure

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages