来一段shell 自动提取吧
- 新建一个.sh 文件
touch test.sh
-
chmod 777 test.sh
-
copy进去
#!/bin/bash
//定义合并文件方法
list_alldir(){
// 1.递归文件目录
for file2 in `ls -A $1`
do
if [ -d "$1/$file2" ];then
#echo "$1/$file2"
list_alldir "$1/$file2"
elif [ -f "$1/$file2" ];then
#2.如果后缀是.swift,合并文件
if [[ "$1/$file2" == *.swift ]] ;then
#echo "\n" >> out.txt
#echo "$1/$file2" >> out.txt
#echo "\n" >> out.txt
cat "$1/$file2" >> out.txt
fi
fi
done
}
# 这里指定为桌面了为指定的文件夹 从哪个文件夹提取
list_alldir /Users/Charlotte/Desktop/DemoShop
- 运行脚本后就可以得到一个out.txt
# cd .sh 文件目录下
./test.sh
网友评论