#filename #directory #file #rollback #name #change #operations

bin+lib fdn

一个用于统一更改文件或目录名称并支持撤销这些操作的工具

12 个版本

0.8.5 2024 年 7 月 11 日
0.8.4 2024 年 4 月 23 日
0.8.2 2024 年 3 月 17 日
0.7.9 2024 年 3 月 6 日
0.6.12 2024 年 1 月 19 日

#728解析实现

Download history 257/week @ 2024-04-20 19/week @ 2024-04-27 1/week @ 2024-05-04 5/week @ 2024-05-18 1/week @ 2024-05-25 1/week @ 2024-06-01 2/week @ 2024-06-08 93/week @ 2024-07-06 14/week @ 2024-07-13 1/week @ 2024-07-20 52/week @ 2024-07-27

每月 160 次下载

MIT/Apache

55KB
1K SLoC

fdn

简介

一个用于统一更改文件或目录名称并支持撤销这些操作的工具。

文件或目录名称格式

  1. 文件名中不允许有空格(首先每个空格将被下划线替换,然后多个连续的下划线将被合并为一个);
  2. 文件名中仅允许使用下划线,其他所有控制字符将被替换为下划线;
  3. 多个连续的下划线将被合并为一个;
  4. 文件名开头下划线将被删除;
  5. 文件名结尾下划线将被删除;
  6. 保留 bash 特殊参数 在文件名中;
  7. 一些术语将保留(持续更新),例如 USBPCIe ...

安装

通过 cargo 安装 fdn

$ cargo install fdn

用法/参数

Usage:
   fdn [OPTIONS] [COMMAND]
Commands:
   config Config pattern help Print this message or the help of the given subcommand(s)
Options:
   -f, --file-path <FILE_PATH> file path [default: .]
   -i, --in-place in place
   -d, --max-depth <MAX_DEPTH> max depth [default: 1]
   -t, --filetype <FILETYPE> file type,'f' for regular file and 'd' for directory [default: f]
   -I, --not-ignore-hidden not ignore hidden file
   -X, --exclude-path <EXCLUDE_PATH> exclude file or directory
   -r, --reverse reverse change
   -a, --align align origin and edited
   -V, --version print version
   -h, --help Print help
Use "fdn [command] --help" for more information about a command.

注意!

当你运行 fdn 时,你会看到两种类型的输出

  • 第一种类型

    sample▯file▯name -->sample_file_name

输出表示:文件名 sample file name 将被更改为 sample_file_name --> 表示在干燥运行模式下,操作不会生效。《》字符表示空格,每个空格将被替换为一个 字符“▯”仅用于视觉对比,仅在输出中显示。 或者

  • 第二种类型

    sample▯file▯name ==>sample_file_name

输出表示:文件名 sample file name 已经更改为 sample_file_name ==> 表示操作已经生效。所有删除的字符将以红色显示,例如原始文件名: sample ▯ file ▯ name 所有添加的字符将以绿色显示,例如更改后的文件名: sample * file * name

选项

-d 选项

执行命令:$ fdn tgt_root -f -t dir -d 2 tgt_root/test目录/$0_T\▯Only -->tgt_root/test目录/$0_T_Only tgt_root/!临时文件夹 -->tgt_root/LSW 临时文件夹 tgt_root/_is▯dir▯% -->tgt_root/Is_dir% tgt_root/测试@#文件夹 -->tgt_root/CS 测试文件夹 tgt_root/test▯directory -->tgt_root/Test_Directory tgt_root -->Tgt_Root ************ 为了生效,请添加选项 '-i' 或 '-c'

$ fdn tgt_root -f -t dir -d 1
   tgt_root/!临时文件夹
-->tgt_root/LSW临时文件夹
   tgt_root/_is▯dir▯%
-->tgt_root/Is_dir_%
   tgt_root/测试@#文件夹
-->tgt_root/CS测试_文件夹
   tgt_root/test▯directory
-->tgt_root/Test_Directory
   tgt_root
-->Tgt_Root
********************************************************************
In order to take effect,add option '-i' or '-c'

-t 选项

$  fdn tgt_root -f -t dir
   tgt_root/!临时文件夹
-->tgt_root/LSW临时文件夹
   tgt_root/测试@#文件夹
-->tgt_root/CS测试_文件夹
   tgt_root/test▯directory
-->tgt_root/Test_Directory
   tgt_root/_is▯dir▯%
-->tgt_root/Is_dir_%
********************************************************************
In order to take effect,add option '-i' or '-c'

$ fdn tgt_root -f
   tgt_root/thi_Is_File_%.mp4
-->tgt_root/Thi_Is_File_%.mp4
   tgt_root/$0▯▯测试用文件.html
-->tgt_root/$0_测试用文件.html
********************************************************************
In order to take effect,add option '-i' or '-c'

-i 选项

$ fdn tgt_root/\$0\ \ 测试用文件.html -io
   $0▯▯测试用文件.html
==>$0_测试用文件.html

-c 选项

$ fdn tgt_root/\$0\ \ 测试用文件.html -c
$0  测试用文件.html
Please confirm(y/n/A/q) [no]:
   $0▯▯测试用文件.html
-->$0_测试用文件.html

$ fdn tgt_root/\$0\ \ 测试用文件.html -c
$0  测试用文件.html
Please confirm(y/n/A/q) [no]: y
   $0▯▯测试用文件.html
==>$0_测试用文件.html

-l 选项

此选项

-f 选项

$ fdn tgt_root/\$0\ \ 测试用文件.html
   $0▯▯测试用文件.html
-->$0_测试用文件.html
********************************************************************
In order to take effect,add option '-i' or '-c'

$ fdn tgt_root/\$0\ \ 测试用文件.html -f
   tgt_root/$0▯▯测试用文件.html
-->tgt_root/$0_测试用文件.html
********************************************************************
In order to take effect,add option '-i' or '-c'

-a 选项

$ fdn
   a▯Test-file.txt
-->A_Test_File.txt
********************************************************************
In order to take effect,add option '-i' or '-c'

$ fdn -a
   /home/hma/a▯Test-file.txt
-->/home/hma/A_Test_File.txt
********************************************************************
In order to take effect,add option '-i' or '-c'

-r 选项

$ fdn tgt_root/\$0_测试用文件.html -r
   $0_测试用文件.html
-->$0▯▯测试用文件.html
********************************************************************
In order to take effect,add option '-i' or '-c'

-o 选项

$ fdn tgt_root/\$0\ \ 测试用文件.html -i
Exist:$0_测试用文件.html
Skipped:$0  测试用文件.html
With option '-o' to enable overwrite.

$ fdn tgt_root/\$0\ \ 测试用文件.html -io
   $0▯▯测试用文件.html
==>$0_测试用文件.html

-p 选项

$ fdn tgt_root
   thi_Is_File_%.mp4
-->Thi_Is_File_%.mp4
   $0▯▯测试用文件.html
-->$0_测试用文件.html
********************************************************************
In order to take effect,add option '-i' or '-c'

$ fdn tgt_root -p
   thi_Is_File_%.mp4
-->Thi_Is_File_%.mp4
   $0▯▯测试用文件.html
-->$0 _测试用文件.html
********************************************************************
In order to take effect,add option '-i' or '-c'

-e 选项

$ fdn tgt_root/\$0_测试用文件.html -re
   $0_测试用文件.html
-->$0▯▯测试用文件.html
********************************************************************
In order to take effect,add option '-i' or '-c'

示例/示例

修改一个文件名/修改一个文件名

$ fdn tgt_root/\$0\ 测试用文件.html
   $0▯测试用文件.html
-->$0_测试用文件.html
********************************************************************
In order to take effect,add option '-i' or '-c'

修改指定目录下文件名/修改指定目录下文件名

$ fdn tgt_root
   $0▯测试用文件.html
-->$0_测试用文件.html
   This▯is▯a▯Test▯file.pdf
-->This_Is_A_Test_File.pdf
   _thi▯is▯file▯%.mp4
-->thi_Is_File_%.mp4
   这是测试文件▯.jpg
-->ZSC这是测试文件.jpg
********************************************************************
In order to take effect,add option '-i' or '-c'

撤销一个文件名的修改/撤销一个文件名的修改

$ fdn tgt_root/\$0_测试用文件.html -r
   $0_测试用文件.html
-->$0▯测试用文件.html
********************************************************************
In order to take effect,add option '-i' or '-c'

撤销目录下文件名的修改/撤销目录下文件名的修改

$ fdn tgt_root -r
   This_Is_A_Test_File.pdf
-->This▯is▯a▯Test▯file.pdf
   ZSC这是测试文件.jpg
-->这是测试文件▯.jpg
   thi_Is_File_%.mp4
-->_thi▯▯is▯▯▯file▯%.mp4
   $0_测试用文件.html
-->$0▯测试用文件.html
********************************************************************
In order to take effect,add option '-i' or '-c'

fd 工具联合工作/与 fd 工具联合工作

fd 是一个用于在文件系统中查找条目的程序。它是一个简单、快速且用户友好的 find.* 替代品。

$ fdfind -HIi html -x fdn -p {}
   $0▯▯测试用文件.html
-->$0_测试用文件.html
********************************************************************
In order to take effect,add option '-i' or '-c'

$ fdfind -HIi html -x fdn -pf {}
   tgt_root/$0▯▯测试用文件.html
-->tgt_root/$0 _测试用文件.html
********************************************************************
In order to take effect,add option '-i' or '-c'

简介

一个小工具,用于日常统一更改文件(或文件夹)名称。

目前的具体格式:

  1. 文件名不保留空格(首先空格会被替换为下划线,之后根据是否存在连续下划线来决定缩减);
  2. 文件名中只保留下划线字符,其余的控制类字符会被替换为下划线;
  3. 多个连续的下划线字符会被缩减为一个下划线;
  4. 如果文件名首字符为下划线将会被删除;
  5. 除去扩展名后的文件名如果最后一个字符是下划线也会被删除;
  6. 在文件名中保留 bash 特殊参数 ;
  7. 文件名中包含的一些术语会保留术语本身的大小写写法(持续更新中...​),例如 USB,PCIe 等;

安装

建议使用cargo进行安装。

$ cargo install fdn

参数

请前往使用/参数 查看。

示例

参考 示例/示例 查看。

依赖

~30–42MB
~652K SLoC