• Post Reply Bookmark Topic Watch Topic
  • New Topic

Retrieve Folder and File Information

 
Rodricks george
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Sir,
This is my folder Structure in My PC... I want to retrieve the Folder Path information From D:/LIC/JeevanSurabhi/Mumbai0000290 this level.
Root Folder Array Should have RootFolder
SubFolder Array Should have Folder1,Folder2,Folder3
Files arrays should have file information of Subfolders


D:/
|-- LIC/
|-- JeevanSurabhi/
|--- Mumbai0000290
|----RootFolder
|--- Folder1 - n number of files
|--- Folder2 - n number of files
|--- Folder3 - n number of files

please give some idea

-Rodricks
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The File class has the methods you need. Create a File with the root directory for your tree, look for a list method to get the file and folders in it, and iterate the list. Are you comfortable with recursion to drill down to sub-folders? If not, this is a great place to learn it.

See how far you can get with the File class. Post some code and show us what you make! If you get stuck, we'll try to get you moving again.
 
Rodricks george
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Sir,

I have done that today morning

static void listContents(File dir,String workingDirectory) {
String[] files; // List of names of files in the directory.
System.out.println("Directory \"" + dir.getName() + "\":");
files = dir.list();
for (int i = 0; i < files.length; i++) {

// If the file is a directory, list its contents
// recursively. Otherwise, just print its name.
File f = new File(dir, files[i]);
if (f.isDirectory())
{
int folderIndex = files[i].toString().lastIndexOf("\\");
String folderName = files[i].toString().substring(folderIndex+1,files[i].toString().length());
System.out.println("Susbstirng Foldername"+folderName);
//create folder in linux

c.unixFolderCreate(workingDirectory, folderName);
String newWorkingDirectory=workingDirectory+"/"+folderName;
listContents(f,newWorkingDirectory);
}
else
{
//Upload the file to linux
up.getLocalDataFiles("192.168.59.180", "xxxxx","xxxxx123", dir.toString(),workingDirectory );

}
}


Thanks you very much

-Rodricks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!