import java.io.File;
/**
*
* @author zhangfj07372
* @time 20111221
*自动扫描文件夹下的文件
*用途:自动扫描脚本输入路径,输出要执行的sql导入数据库;
*/
public class OutSql {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String path ="F:\\sql";
GetSql(path);
}
/*
* 递归调用查找指定文件加下所有文件
*/
public static String GetSql(String path){
File rootDir = new File(path);
if(!rootDir.isDirectory()){
System.out.println("文件名"+rootDir.getAbsolutePath());
}else{
String[] fileList = rootDir.list();
for (int i = 0; i < fileList.length; i++) {
path = rootDir.getAbsolutePath()+"];
GetSql(path);
}
}
return null;
}
/**
* 非递归查找所有文件
消除递归 用到栈的思想;
*/
public static void prinDir(File dir) {
Stack stack = new Stack();
stack.push(dir);
while(!stack.isEmpty()){
File tdFile = (File) stack.pop();
System.out.println("文件夹名:" + tdFile.getAbsolutePath());
String[] ssStrings= tdFile.list();
for(String ts:ssStrings){
File tdFile2 = new File(tdFile,ts);
if(tdFile2.isDirectory()){
stack.push(tdFile2); //压栈
}else{
System.out.println("文件名:" + tdFile2.getName());
}
}
}
}
}