endef 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/de.sh +22 -29
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "endef",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Encrypt or Decrypt Files Test",
5
5
  "bin": {
6
6
  "endef": "bin/main.js"
package/src/de.sh CHANGED
@@ -1,34 +1,27 @@
1
1
  #!/bin/bash
2
2
 
3
- DIR=$1
4
-
5
- remove_suffix() {
6
- local directory=$1
7
-
8
- # 使用 find 命令查找以 . 开头的文件
9
- while IFS= read -r -d '' file; do
10
- # 获取文件名和目录路径
11
- filename=$(basename "$file")
12
- dir=$(dirname "$file")
13
-
14
- # 移除后缀
15
- new_filename=${filename%%._$_foobar*}
16
-
17
- # 构建新的文件路径
18
- new_file="$dir/$new_filename"
19
-
20
- # 重命名文件
21
- mv "$file" "$new_file"
22
-
23
- echo "File renamed: $new_file"
24
- done < <(find "$directory" -type f \( -name ".*" -o -empty \) -print0)
25
-
26
- # 递归处理子目录
27
- find "$directory" -mindepth 1 -maxdepth 1 -type d -not -name ".*" -print0 | while IFS= read -r -d '' subdir; do
28
- remove_suffix "$subdir"
29
- done
3
+ # 处理文件名并重命名
4
+ process_filename() {
5
+ local file=$1
6
+ local filename=$(basename "$file")
7
+ local dir=$(dirname "$file")
8
+
9
+ # 判断文件名是否以指定字符串结尾
10
+ if [[ $filename =~ \._\$_foobar$ ]]; then
11
+ local new_filename=${filename%%._$_foobar*} # 移除指定字符串
12
+ local new_path="$dir/$new_filename" # 构建新的文件路径
13
+
14
+ mv "$file" "$new_path" # 重命名文件
15
+ echo "Renamed: $filename -> $new_filename"
16
+ fi
30
17
  }
31
18
 
32
- directory="$DIR" # 替换为你的目录路径
19
+ # 指定目标目录
20
+ directory="$1" # 替换为您的目录路径
21
+
22
+ # 导出函数以便在并行处理中使用
23
+ export -f process_filename
33
24
 
34
- remove_suffix "$directory"
25
+ # 处理文件名并重命名(并行处理)
26
+ find "$directory" -type f -print0 | \
27
+ xargs -0 -P "$(nproc)" -I{} bash -c 'process_filename "$@"' _ {}