Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 13th, 2008, 04:39 PM
ROMIOs ROMIOs is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 1 ROMIOs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 57 sec
Reputation Power: 0
Question Need a beginner help (showing list of files and folders in a directory)

hey ..
im asked to show -using java- the list of directories and files in a specified directory. but if in that directory an other directory exists it lists under it its files and directories.
i could do this by the following code:

Code:
import java.io.File;
public class Explore {
    public void getList(String dir_path) {
    	File f = new File(dir_path);
		String[] list = f.list();
		File tmp;		
		for(int i=0; i<list.length; i++)
		{
			tmp = new File(dir_path+"\\"+list[i]);
			if(tmp.isFile())
			{
				System.out.println("File: "+list[i]);
			}
			else
			{
				System.out.println("Dir: "+list[i]);
				getList(tmp.getPath());
			}
		}
    }
    public static void main(String[] args)
    {
		String path = "C://Documents and Settings//user//Desktop//Test";
    	Explore e = new Explore();
    	e.getList(path);
    }
    
}


for now it's Okayy :

Code:
Dir: Farida
File: haha.txt
File: secondFile.docx
Dir: Rami
Dir: 3abiit
File: dddl.txt
File: hii.txt
File: SA.JAVA


but i need to show them as follow:

Code:
Dir: Farida
	File: haha.txt
	File: secondFile.docx
Dir: Rami
	Dir: 3abiit
		File: dddl.txt
		File: hii.txt
File: SA.JAVA


thx in advance

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Need a beginner help (showing list of files and folders in a directory)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT