Skip to content

Renaming Commands

LavaAfterburner edited this page Jun 10, 2019 · 3 revisions

Renaming Commands

Renaming commands allow for easy and compact renaming functions, useful for the Folder.collapse ( ), Folder.rename_files ( ), ... methods

Example

Adding the creation date to all files in the folder:

example
├── a.txt
├── test
│   ├── a.txt
│   ├── b.txt
│   ├── temp
│   │   ├── a.txt
│   │   ├── b.txt
│   │   └── c.txt

We can achieve that with the following program:

from fl import File, Folder, Example

# Create the example folder structure:  
Example.create_nested_with_duplicates()

# Add the date
d = Folder("./example/")
d.rename_files("%B %TCd-%TCb-%TCY%E")

Result:

example
├── a 10-Jun-2019.txt
├── test
│   ├── a 10-Jun-2019.txt
│   ├── b 10-Jun-2019.txt
│   ├── temp
│   │   ├── a 10-Jun-2019.txt
│   │   ├── b 10-Jun-2019.txt
│   │   └── c 10-Jun-2019.txt

Renaming commands begin with a % followed by one or more characters. They are executed for every file individually, and can add special data to the name (like the creation date). You can use a "normal" string between the commands, e.g. "My file is called %B with the extension %E"

Commands

  • %B - Name of the file (without extension type) or folder
  • %E - Extension type of the file (with .)
  • %C[...] - Collapsed folder names joined with the given sequence between [ and ]
  • %T - Time
    • %TC - Creation Time
    • %TM - Modified Time
    • %TA - Access Time
    • %TL - "Least Time" minimum time of Creation Time, Modified Time, Access Time, in case a file is corrupt

To use the Time commands you have to add a datetime formatting code. E.g.

"%TCd-TCm-TCY" # "09-06-2019"
"%B %TMY" # "MyFile 2019"
Clone this wiki locally