• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

Adding distinct filenames to a string array

Hi there
I have a folder which i want to add the contents of it to a string array. However some of the files have the same name but a different file extension eg foo.txt and foo.zip
I have being using
File fileList = new File(path);
String[] projects = fileList.list();

but it is no use anymore as it shows two files instead of one. I just want one entry of each  distinct filename in the string array. Ive being trying to use a filefilter but to na avail. Your help is appriciated.
 
0
illumin
Asked:
illumin
1 Solution
 
schybertCommented:
I'm confused... you don't want to show all the files in the directory? foo.zip and foo.txt are after all distinct file names...
0
 
illuminAuthor Commented:
Ok ill try to explain it better... I have two files in a dir called foo.txt and foo.zip .I only want to add one foo to the string array instead of two. The code that ive come up with so far still shows up two foo's :(

package mypackage;
import java.io.*;

public class ZipFilter implements FilenameFilter
{  
  public boolean accept(File dir,String name)
   {  
    return(name.endsWith(".zip"));
   }
}

String path = (String)session.getAttribute("Path");
  File fileList = new File(path);
  ZipFilter filter = new ZipFilter();
  fileList.list(filter);
0
 
illuminAuthor Commented:
String[] projects = fileList.list(); should be on the end of the las comment
The second block of code is in a different class :P
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
illuminAuthor Commented:
Sorry i am so stupid i was doing this
String[] projects = fileList.list();

instead of this

 String[] projects = fileList.list(filter);

It works fine for me now ...
0
 
schybertCommented:
hehe, great
0
 
illuminAuthor Commented:
Can any mods delete this question please
0
 
CleanupPingCommented:
illumin:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
NetminderCommented:
User resolved; points refunded and question closed.

Netminder
EE Admin
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now