项目作者: Inspiaaa

项目描述 :
Python File Library is a collection of methods and classes to make working with files easier
高级语言: Python
项目地址: git://github.com/Inspiaaa/Python-File-Library.git
创建时间: 2019-06-09T08:45:43Z
项目社区:https://github.com/Inspiaaa/Python-File-Library

开源协议:

下载


Python 3.7

FL - Python File Library

FL enables many high level operations on Files and Folders in an OOP style.
For example: Flattening, Renaming, Recursively Moving / Copying / Deleting, …

Getting Started

Prerequisites

A working version of Python 3.7


Example

Basic flattening of a folder

We create the folder structure:

  1. example
  2. ├── a.txt
  3. ├── test
  4. ├── b.txt
  5. ├── temp
  6. └── c.txt

… and want to flatten it to:

  1. example
  2. ├── a.txt
  3. ├── b.txt
  4. └── c.txt

We can achieve that with the following code:

  1. from fl import File, Folder, Example
  2. # Create the example nested folder structure with some files
  3. Example.create_simple_nested()
  4. # Collapse (Flatten) the folder structure
  5. d = Folder("./example/")
  6. d.collapse()

Adding the creation date to each file

Adding the creation date to all files in the folder:

  1. example
  2. ├── a.txt
  3. ├── test
  4. ├── a.txt
  5. ├── b.txt
  6. ├── temp
  7. ├── a.txt
  8. ├── b.txt
  9. └── c.txt

To do this, we can run following program:

  1. from fl import File, Folder, Example
  2. # Create the example folder structure:
  3. Example.create_nested_with_duplicates()
  4. # Add the date
  5. d = Folder("./example/")
  6. d.rename_files("%B %TCd-%TCb-%TCY%E")

This program uses special renaming commands to add special data (e.g. Date). To visualize the result in the console, the folder class offers a method to print it:

  1. d = Folder("./example/")
  2. d.print_beautified()

Console:

  1. example
  2. ├── a 10-Jun-2019.txt
  3. ├── test
  4. ├── a 10-Jun-2019.txt
  5. ├── b 10-Jun-2019.txt
  6. ├── temp
  7. ├── a 10-Jun-2019.txt
  8. ├── b 10-Jun-2019.txt
  9. └── c 10-Jun-2019.txt

Documentation

Get started with the documentation here.