函数名: remove
用 法: int remove(char *filename)
程序例:
#include <stdio.h>int main(void)
{
char file[80]
/* prompt for file name to delete */
printf("File to delete: ")
gets(file)
/* delete the file */
if (remove(file) == 0)
printf("Removed %s.\n",file)
else
perror("remove")
return 0
}
#!/bin/bash //声明使用的shellPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin//usr/local/sbin:~/bin
export PATH
read -p "Please input your directory name:" d_name //d_name让你输入目录名
if[ "$d_name" == "" ] || [ ! -d "$d_name" ]then//没输入,或者不是目录,退出
echo -e "The director is not exist,please check it"
exit 1
fi
filelist=`ls $d_name` //filelist 为该目录下的所有文件,包括普通文件和目录文件
for filename int $filelist //shell for 循环
do
if[ -f $filename ]then //是文件,删除,不是,继续循环,到结束
rm -rf $filename
fi
done
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)