-
Notifications
You must be signed in to change notification settings - Fork 0
Resolving renaming conflicts
F2 tries to prevent common renaming problems by analysing the target destinations for conflicts and other potential problems.
The following problems are detected automatically for each renaming operation:
- When two files are renamed to the same name.
- When the new name of a file contains forbidden characters (varies depending on the OS).
- When a file is renamed to the name of an existing file.
- When the name of a file maximum allowed length (255 characters in Windows, and 255 bytes on Unix).
- When the target destination contains trailing periods (Windows only).
- When the new filename is empty.
If any of the above problems are detected, the renaming operation fails and all the problematic files are listed out for inspection. The renaming operation cannot proceed unless the errors are fixed.
-
Renaming two files to the same path:
f2 -f "Screenshot from (.*)\.png" -r '{<$1>.dt.YYYY}/{<$1>.dt.MMMM}/Screenshot{ext}'
┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐ | ORIGINAL | RENAMED | STATUS | | **************************************************************************************************** | | Screenshot from 2022-04-12 14:37:35.png | 2022/April/Screenshot.png | overwriting newly renamed path | | Screenshot from 2022-04-12 15:58:55.png | 2022/April/Screenshot.png | overwriting newly renamed path | └──────────────────────────────────────────────────────────────────────────────────────────────────────┘
-
Renaming to an empty filename
f2 -f "Screenshot from (.*)\.png"
┌────────────────────────────────────────────────────────────────────┐ | ORIGINAL | RENAMED | STATUS | | ****************************************************************** | | Screenshot from 2022-04-12 14:37:35.png | | empty filename | | Screenshot from 2022-04-12 15:58:55.png | | empty filename | | Screenshot from 2022-06-03 11:29:16.png | | empty filename | | Screenshot from 2022-09-26 21:19:15.png | | empty filename | └────────────────────────────────────────────────────────────────────┘
Fixing each problem manually can be tedious and time consuming, so F2 provides a
way to automatically fix all conflicts at once! You should include the
--fix-conflicts
or -F
flag in the renaming conflict.
Here's how F2 fixes each type of conflict:
f2 -f 'a' -r 'b'
┌──────────────────────────────────────────┐
| ORIGINAL | RENAMED | STATUS |
| **************************************** |
| a.txt | b.txt | path already exists |
└──────────────────────────────────────────┘
This conflict is automatically fixed by adding a number suffix to the target destination to differentiate it from the existing one.
f2 -f "a" -r "b" -F
┌───────────────────────────────┐
| ORIGINAL | RENAMED | STATUS |
| ***************************** |
| a.txt | b (2).txt | ok |
└───────────────────────────────┘
f2 -f 'a|b' -r 'c'
┌─────────────────────────────────────────────────────┐
| ORIGINAL | RENAMED | STATUS |
| *************************************************** |
| a.txt | c.txt | overwriting newly renamed path |
| b.txt | c.txt | overwriting newly renamed path |
└─────────────────────────────────────────────────────┘
This conflict is automatically resolved by an incrementing number suffix (staring at 2) to all target names except the first one to differentiate them accordingly.
f2 -f 'a|b' -r 'c' -F
┌───────────────────────────────┐
| ORIGINAL | RENAMED | STATUS |
| ***************************** |
| a.txt | c.txt | ok |
| b.txt | c (2).txt | ok |
└───────────────────────────────┘
f2 -f 'a.txt' # replacement will be an empty string if omitted
┌─────────────────────────────────────┐
| ORIGINAL | RENAMED | STATUS |
| *********************************** |
| a.txt | | empty filename |
└─────────────────────────────────────┘
This conflict is automatically fixed by by leaving the file name unchanged.
f2 -f 'a.txt' -F
┌────────────────────────────────┐
| ORIGINAL | RENAMED | STATUS |
| ****************************** |
| a.txt | a.txt | unchanged |
└────────────────────────────────┘
f2 -f 'a' -r 'c:'
┌──────────────────────────────────────────────────────┐
| ORIGINAL | RENAMED | STATUS |
| **************************************************** |
| a.txt | c:.txt | invalid characters present: (:) |
└──────────────────────────────────────────────────────┘
The conflict is automatically fixed by removing all the offending characters from the target path.
f2 -f 'a' -r 'c:' -F
┌─────────────────────────────┐
| ORIGINAL | RENAMED | STATUS |
| *************************** |
| a.txt | c.txt | ok |
└─────────────────────────────┘
Windows does not allow trailing periods in a file name or directory name so they are auto detected as problems:
f2 -f 'a' -r 'new../a'
┌──────────────────────────────────────────────────────────┐
| ORIGINAL | RENAMED | STATUS |
| ******************************************************** |
| a.txt | new../a.txt | trailing periods are prohibited |
└──────────────────────────────────────────────────────────┘
This conflict is automatically fixed by removing the trailing periods.
f2 -f 'a' -r 'new../a' -F
┌───────────────────────────────┐
| ORIGINAL | RENAMED | STATUS |
| ***************************** |
| a.txt | new/a.txt | ok |
└───────────────────────────────┘
This conflict is automatically fixed by stripping characters from the end of the destination path until its length no longer exceeds the maximum allowed number.