Computing.Net > Forums > Programming > Java - Order of files in directory

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Java - Order of files in directory

Reply to Message Icon

Name: gometro33
Date: October 29, 2006 at 15:20:59 Pacific
OS: Mac 10.4.7
CPU/Ram: 2 GHz / 1 GB
Product: Apple
Comment:

I have directory of files that are named, for example, page1.txt, page2.txt,...I have a lot of them (more than 1000).

When I use

File f = new File("path_to_directory");
String[] list = f.list();

I get a list of files but they are out of order. Instead of being page1.txt, page2.txt...it comes out as page1.txt, page10.txt, page100.txt, etc.

Basically, how can I sort the array so that it is in the correct order?

A few things to note:
1. the naming scheme will no always be page + number + .txt but there will always be a pattern somewhere in the file name
2. OSX, Windows, and Linux all are able to show the files in the correct order in the GUI but not when you do it in the terminal (cd path_to_directory then ls).

Thanks for the help, and ask questions if you need clarification on something.

-Matt



Sponsored Link
Ads by Google

Response Number 1
Name: gometro33
Date: October 29, 2006 at 19:21:19 Pacific
Reply:

Actually, I figured it out. Thanks though.

-Matt


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Java - Order of files in directory

Count number of files in directory www.computing.net/answers/programming/count-number-of-files-in-directory-/15868.html

Move half of files in one directory to other www.computing.net/answers/programming/move-half-of-files-in-one-directory-to-other/19059.html

count no of files in a directory www.computing.net/answers/programming/count-no-of-files-in-a-directory/18316.html