Friday, November 2, 2012

Delete all files in a folder


/*
 * LoadRunner Java script. (Build: 946)
 *
 * Script Description:
 *                    
 */

import lrapi.lr;
import java.io.*;

public class Actions
{

public int init() throws Throwable {
return 0;
}//end of init


public int action() throws Throwable {


   String dirPath="D:\\OrderIDs\\Copyof20090407\\"; //change the Directory accordingly
   File dir_path = new File(dirPath);
   File[] files = dir_path.listFiles();

   for(int i=0; i < files.length; i++){
   String fileName = files[i]+"";

File f1 = new File(fileName);
boolean success = f1.delete();

if (!success){
 System.out.println("Deletion failed.");
 System.exit(0);
}else{
 System.out.println(fileName + " - deleted.");
}
   }

return 0;
}//end of action


public int end() throws Throwable {
return 0;
}//end of end
}

No comments:

Post a Comment