The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Re: How to List all files in a directory

good job friends.

the code which is written by javapf is
can be modify
i think the if code totlly write into a function
we will display the files if it is a file other wise we call recursively that function again
we can get all files and folders recursivly with that method.
bye guys.

Re: How to List all files in a directory

I know I am fairly new to Developing with java but I feel you could change the line

if (files.endsWith(".txt") || files.endsWith(".TXT"))

with

if (files.toLowerCase().endsWith(".txt"))

and this way you can exclude the or statement ( || ) and allow for any possible variation in the extension, .txt / .Txt / .tXt / .tXT / .TXT / .TXt (I think that is all), I think it will make for cleaner and more defined code, and that way no matter how ever the casing is you can still get all the possible files with that extension. Let me know if I am wrong...But I love the example... Below is the changed code: