python批量删除.pyc文件以及test文件夹
将文件内容保存为removepyc.sh,然后执行./removepyc.sh,会将次目录下的所有pyc文件以及test文件夹删除掉
#!/bin/bash
remove_file_prefix=.pyc
function getfile(){
for e in `ls $1`
do
fullpath=$1/$e
if [ -f $fullpath ]; then
prefix=${fullpath:0-4}
if [ "$prefix" == "$remove_file_prefix" ]; then
echo delete file:$fullpath
rm -rf $fullpath
fi
elif [ -d $fullpath ]; then
if [ "$e" == "test" ]; then
echo delete dir:$fullpath
git rm -rf $fullpath
else
getfile $fullpath
fi
fi
done
}
read -p "Are you sure you want to delete all $remove_file_prefix files?[Y]:" flag
if [[ ! $flag || "$flag" == "Y" || "$flag" == "y" ]]; then
getfile .
fi
还没有评论,来说两句吧...