• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Take files input from directory as listed in Windows Explorer window

 
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm writing a code where in there a bunch of files that have to be taken as input from a directory.

The program works fine, but the problem comes up in the way the files are picked. In my directory when I do a sort the first file shown is file5521.3, but in my program the first file that is picked up is file5521.100. THis is pretty confusing.

I've also tried using Arrays.sort(list, NameFileComparator.NAME_COMPARATOR), but it also gives the same result as previous.

Below is my code.


please let me know how can I do this.

Working Solution with Last Modified Date


The Comparator works fine with last modified date, but when I try it with below code. The result is same as previous.




In my Windows Explorer It looks like the Windows Image.


And my console output shows Console Image.

I'm using Windows 7.

Thanks,
Marsoni
WinImg.jpg
[Thumbnail for WinImg.jpg]
Windows Image
ConsoleImg.jpg
[Thumbnail for ConsoleImg.jpg]
Console Image
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But file5523.100 is always before file5523.3.
If you want the files to be sorted by the numeric value of the extension rather than by their names, you will have to write a Comparator for the two parts of the file nam.
 
Marsoni Hutao
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:But file5523.100 is always before file5523.3.
If you want the files to be sorted by the numeric value of the extension rather than by their names, you will have to write a Comparator for the two parts of the file nam.



You mean that I've to consider filename after the period?
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.
 
Marsoni Hutao
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Yes.



Sorry for the delayed reply. Thank you soo much. This worked for me

For those who have similar problem, here is the solution.


Cheers
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Marsoni Hutao wrote:. . . Sorry for the delayed reply. Thank you soo much. This worked for me . . .

That's a pleasure and well done and thank you for posting the solution
 
reply
    Bookmark Topic Watch Topic
  • New Topic