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.
- package/package.json +1 -1
- package/src/de.sh +22 -29
package/package.json
CHANGED
package/src/de.sh
CHANGED
|
@@ -1,34 +1,27 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
local
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
filename
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
#
|
|
15
|
-
|
|
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
|
-
|
|
19
|
+
# 指定目标目录
|
|
20
|
+
directory="$1" # 替换为您的目录路径
|
|
21
|
+
|
|
22
|
+
# 导出函数以便在并行处理中使用
|
|
23
|
+
export -f process_filename
|
|
33
24
|
|
|
34
|
-
|
|
25
|
+
# 处理文件名并重命名(并行处理)
|
|
26
|
+
find "$directory" -type f -print0 | \
|
|
27
|
+
xargs -0 -P "$(nproc)" -I{} bash -c 'process_filename "$@"' _ {}
|