JSP tutorial shows all files and subdirectory code under the directory
public static void GetFiles (list<file> filelist, string path, string filesuffix) {
File File = new file (path);
file[] files = file.listfiles ();
if (files = null) {
Return
} else {
for (int i = 0; i < files.length; i++) {
Determine if it is a folder
if (Files[i].isdirectory ()) {
Recursive call GetFiles method to get all the files
GetFiles (FileList, Getavailablepath (files[i)), filesuffix);
else if (Files[i].getname (). LastIndexOf (Filesuffix)!=-1) {//document that handles only filesuffix suffixes
Copyfileandaddpackagename (Files[i]);
Filelist.add (Files[i]);//Add to file collection
}
}
}
}
Method two JSP deletes all folders and file code for the directory
Import java.io.*;
public class DeleteAll {//Delete all contents under folder, including this folder
public void Delall (File f)
Throws IOException {
if (!f.exists ())//folder does not exist throw new IOException (specified directory does not exist: +f.getname ());
Boolean rslt=true;//Save Intermediate results
if (!) ( Rslt=f.delete ()) {//First try to delete//If the folder is not empty. Enumerate, recursively delete contents inside
File subs[] = F.listfiles ();
for (int i = 0; I <= subs.length-1; i++) {
if (Subs[i].isdirectory ())
Delall (Subs[i]);//delete subfolder contents recursively
Rslt = Subs[i].delete ();//delete subfolder itself
}
Rslt = F.delete ();//delete this folder itself
}
if (!RSLT)
throw new IOException (Unable to delete: +f.getname ()); Return
}
public static void Main (string[] args) {
DeleteAll da= new DeleteAll ();
try {
Da.delall (New File (Somedir));
}
catch (IOException ex)
{
Ex.printstacktrace (); }
}}