Sunday, January 14, 2007
Here is a code which will guide u through this.
The bad thing is the file is not still posted :D
import java.io.File;
import javax.swing.*;
import java.io.*;
public class dir
{
FileWriter fr;
dir()
{
try
{
fr=new FileWriter("c:/outputDir.txt");
}
catch (Exception ex)
{
}
}
public static void main(String args[])
{
dir d=new dir();
d.getDirectoryStructure();
//showFileTree("a");
/*FileDescriptor fd=new FileDescriptor();
String location="a";
File f=new File(location);
String[] s=f.list();
File[] ff=f.listFiles();
for(int j=0;j
{
System.out.println (ff[j].getName());
}
for(int i=0;i
System.out.println (s[i]+"Directory: "+new File(location+"/"+s[i]).isDirectory()+"\n");*/
}
void getDirectoryStructure()
{
String str=JOptionPane.showInputDialog("Enter the directory of which u want to get info");
File f=new File(str);
if(f.exists())
{
showFileTree(str);
}
else
{
try
{
this.fr.write("File does not exist");
//this.fr.close();
}
catch (Exception ex) {
}
}
try
{
this.fr.close();
}
catch (Exception ex) {
}
}
int printTab=0;
int count=0;
void showFileTree(String directory)
{
File f=new File(directory);
File[] allFiles=f.listFiles();
for(int i=0;i
{
for(int j=0;j
{
try
{
fr.write("\t");
}
catch (Exception ex) {
}
System.out.print("\t");
}
try
{
String temp=allFiles[i].getName();
temp=temp.substring(0,temp.indexOf("."));
count++;
fr.write("insert into pinyin values("+count+",'"+temp+"');\n");
}
catch (Exception ex) {
}
//System.out.print("Name: "+allFiles[i].getName()+" +length: "+allFiles[i].length()+ "\n");
if(allFiles[i].isDirectory())
{
printTab++;
showFileTree(allFiles[i].getPath());
}
}
printTab--;
}
}