B12:Java Scripts required to start, stop and perform daily cleanup tasks
Program:
import java.io.*;class cleanup
{
public static void main(String[] args) throws FileNotFoundException,UnsupportedEncodingException
{
File file = new File("/root/a/");
String[] myFiles;
int count=0;
if(file.isDirectory()){
myFiles = file.list();
for (int i=0; i<myFiles.length; i++) {
File myFile = new File(file, myFiles[i]);
if(myFile.delete())
{ count++; }
}
}
System.out.println("\n"+count+" Files and Directory are deleted successfully..");
PrintWriter writer =new PrintWriter("/root/log/cleanup_log.txt","UTF-8");
writer.println("\n ----------------------------------------------------");
writer.println("\n"+count+" Files are deleted successfully");
writer.println("\n --------------------x-o-x---------------------------\n");
writer.close();
}
}
0 comments:
Post a Comment