List of Files in a directory

Is there a way that you can get a list of files in a directory that are spelt a certain way? Ex. If in a directory there are html files, txt files, et, In java can I get *.html or a html file with certain text in the name? java.html??
How you can Help
US101

here are the code to list your files
     File startDir = new File("your directory goes here" );
     File[] dirList = startDir.listFiles();
     if (startDir.isDirectory());
     out.print( startDir.getPath() );
          //Start cycling through the array for the file
     for ( int count = 0; count < dirList.length; count++ )
String fileName = dirList[count].getName();
          int index = fileName.lastIndexOf('.');
          String newString = null;
               if (index >= 0)
                    newString = fileName.substring(index, fileName.length());
                    if ( newString.equalsIgnoreCase( ".txt"))
                         if ( dirList[count].isDirectory())
                              out.println( dirList[count].getName() );
                         else
                              out.println( dirList[count].getName());
                         }//end else
                    }// end if newstring
     }//end if index
     }//end for

Similar Messages

  • How to list the files in a directory which are recently modififed few mins

    Hi,
    I need command to list the files in a directory which are modified few minutes ago in SunOS. like "find . -cmin 2 -print " which list files that are modified 2 mins ago in Linux platform.
    Thanks in advance.
    sudha85

    The find command that comes with solaris doesnt have the cmin operator. Only mtime whose option is days.
    So install gnu find from sunfreeware which is the same one that comes with linux.

  • List all files in a directory on a server that hosts the applet

    Hei :)
    I have a problem. I want to list all files in a directory on my server. ( http://www.foo.bar/tw )
    The applet is in the root folder ( http://www.foo.bar ).
    So i tried it like this
    File fi = new URL(getCodeBase() + "/all/").getFile();But when I try to list the files, I get a SecurityException.
    Can anyone help me out?
    Peace!
    LoCal

    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=&qt=%2Blist+%2Bfile+%2Bserver

  • Getting the list of  files in a directory by their last modified date

    Dear friends,
    I want to get the list of files in a directory sorted by their last modified date.
    By default the file.list() or listFiles() return files sorted by their name in ascending order.
    Please give me your suggestions.
    Thanks in advance,
    James.

    Thanks friend,
    I myself got the answer
    here is my code:
    public File[] getSortedFileList(File dir){
    File[] originalList = dir.listFiles();
    int numberOfFiles = originalList.length;
    File[] sortedList = new File[numberOfFiles];
    long[] lastModified = new long[numberOfFiles];
    for(int i = 0; i < numberOfFiles; i++){
    lastModified[i] = originalList.lastModified();
    Arrays.sort(lastModified);
    for(int i = 0; i < numberOfFiles; i++){
    for(int k = 0; k < numberOfFiles; k++){
    if(originalList[k].lastModified() == lastModified[i])
    sortedList[i] = originalList[k];
    System.out.println("The sorted file list is:" + sortedList[i]);
    return sortedList;

  • List of files in a directory of app server

    Hi,
    I was trying to get the list of all files in a directory using fm "EPS2_GET_DIRECTORY_LISTING". But the date column is empty in the output table. I also tried fm's
    SUBST_GET_FILE_LIST
    EPS_GET_FILE_ATTRIBUTES
    none of the above is giving date.
    Can anyone tell me a fm which gives date along with other attributes?
    Thanks in Advance.
    Satish

    try get something from the transaction AL11 source code: RSWATCH0 form -> fill_file_list
    Regards,
    Vincent

  • Problem with getting a list of files in a directory

    I'm trying to get a list of files in a particular directory. The problem is I'm also getting a listing of all the sub-directories too. Here is my code:
    File directory = new File(dir);
    File[] filelist;
    filelist = directory.listFiles();
    for(int i=0;i<filelist.length;i++)
    System.out.println("FileName = " + filelist.getName());
    What am I doing wrong?
    Thanks
    Brad

    You are not doing anything wrong. You just have to test whether a given file is a subdirectory:
    File directory = new File(dir);
    File[] filelist;
    filelist = directory.listFiles();
    for(int n = 0; n < filelist.length; n++) {
      if (!filelist[n].isDirectory())
        System.out.println("FileName = " + filelist[n].getName());
    }S&oslash;ren Bak

  • List all files in a directory, not including the sub directories if any

    Hi,
    I have been looking around php.net for a bit and can not work
    out how i list the files that are in a directory i.e.
    www.site.com/directory/
    I would like the names of each file to be placed in an array,
    but not to have the sub directories in this list should there be
    any.
    I was given some code a while ago that done this but it
    listed the sub directories and i would like them not in this list.
    I do not have this code anymore and do not know where i got
    it, so i can not get it amended to what i need.
    please can someone tell me what line of code i should be
    using.
    thank you in advance for your help.

    (_seb_) wrote:
    > not very clever wrote:
    >> Hi,
    >>
    >> I have been looking around php.net for a bit and can
    not work out how
    >> i list the files that are in a directory i.e.
    >>
    >> www.site.com/directory/
    >>
    >> I would like the names of each file to be placed in
    an array, but not
    >> to have the sub directories in this list should
    there be any.
    >>
    >> I was given some code a while ago that done this but
    it listed the
    >> sub directories and i would like them not in this
    list.
    >>
    >> I do not have this code anymore and do not know
    where i got it, so i
    >> can not get it amended to what i need.
    >>
    >> please can someone tell me what line of code i
    should be using.
    >>
    >> thank you in advance for your help.
    >>
    >>
    >>
    >
    > The follwoing PHP code will do just that. Just replace
    "pathToFolder"
    > with the path to your folder.
    > I made the list of files also link to each file. Just
    remove the link
    > echo if you don't them to be links.
    >
    > <?php
    > // FUNCTION TO LIST FILES:
    > function listFiles($path){
    > if($handle = opendir($path)){
    > while(false !== ($file = readdir($handle))){
    > if (is_file($path.'/'.$file) &&
    !preg_match('/^\./',$file)){
    > $files_array[]=$file;
    > }
    > }
    > }
    > return($files_array);
    > }
    > $path = 'pathToFolder';
    >
    > // CALL THE FUNCTION:
    > $files_array = listFiles($path);
    > foreach($files_array as $file){
    > echo '<p><a
    href="'.$path.'/'.$file.'">'.$file,'</a></p>';
    > }
    >
    > ?>
    >
    I spotted one error:
    foreach($files_array as $file){
    echo '<p><a
    href="'.$path.'/'.$file.'">'.$file,'</a></p>';
    should be:
    foreach($files_array as $file){
    echo '<p><a
    href="'.$path.'/'.$file.'">'.$file.'</a></p>';
    (a dot after $file, not a coma)
    seb ( [email protected])
    http://webtrans1.com | high-end web
    design
    Downloads: Slide Show, Directory Browser, Mailing List

  • How to list specific files in a directory

    Hi. I have a FilanemeFilter derived class which works fine. The problem I have is how do I list the files in the subdirectory of the current directory?
    I wrote sth like this but it doesn't work:
    File dir = new File( File.separator + "components");What am I doing wrong?

    Well, I know it doesn't work becouse I used the JFileChooser to check this out. I gave it as a constructor parameter. According to the docs if the given dir doesn't exist the JFileChooser opens the system default drectory, which under Windows happens to be MyDocuments folder. That's how I know.

  • Creating list of files from a directory

    Hi,
    poked around on the internet, and wanted to be able to create an ArrayList of all files in a directory. This code compiles, but doesn't work:
    import java.io.*;
    import java.util.*;
    public class TestDir {
         public static void main(String[] args){
         File folder = new File("testdir");
         System.out.println("does the folder exist? " + folder.exists());
         System.out.println("is folder a directory? " + folder.isDirectory());
         System.out.println("path: " + folder.getAbsolutePath());
         // create list of files
         try{
         ArrayList<File> files = TestDir.getFileList(folder);
         Iterator i = files.iterator();
         while (i.hasNext()){
         File temp = (File) i.next();
         System.out.println("file: " + temp.getName());
         } catch (IOException e){
         System.err.println("problem creating file list:");
         e.printStackTrace();
         } // end main
         public static ArrayList<File> getFileList(File dir) throws FileNotFoundException{
         ArrayList<File> result = new ArrayList<File>();
         File[] files = dir.listFiles();
         List<File> tempfiles = Arrays.asList(files);
              for(File file : files){
              result.add(file);
         return result;
    } // end classthis compiles fine, but doesn't give me the list of files.
    Any idea what I'm doing wrong?
    bp

    console output:
    C:\jason\java\domPractice>java TestDir
    does the folder exist? true
    is folder a directory? true
    path: C:\jason\java\domPractice\testdir

  • Geting a list of files in a directory

    ok i know how to get it if its in my own drive
    but im haveing trouble doing this from a website.
    im not geting any errors when i try to check the webpage
    on the server it just doesnt even display the applet
    can anyone see what is wrong if i cant see the error's
    i have no way of knowing what im doing wrong
    1.)is url.getPath the correct way to get the path to the directory ?
    2.)can i use the file class as i am to get a list of files on the
    server ?
    String[] availabletexturelist;
    URL url = getDocumentBase();
    String currentpath = url.getPath();
    System.out.println("currentpath = "+currentpath);
    File cdir = new File(currentpath);
    availabletexturelist = cdir.list(new FilenameFilter(){public boolean accept(File d,String name){return name.endsWith(".jpg");}});
    for(int flp = 0;flp < availabletexturelist.length;flp ++){DynamicallyAddTexture(availabletexturelist[flp]);System.out.println(""+availabletexturelist[flp]);} any help is appreciated

    yep my site
    just wanted to be able to have the code read what images are
    in the same directory as the applet and load them all.
    but then the answer would be
    i cant use file to grab a list of files
    that are in the same directory as my applet on the server
    that i am downloading the applet from.
    however is their a way to get the path to just the directory that the
    applet is being downloaded from itself ?
    and then the following is true
    specifying the images that i intend to use in applet parameter tags
    or hardcodeing the imagenames and paths into the code is the easyiest way.
    right ?

  • Get list of files in a directory

    Hello everybody,
    working with Oracle 9.2 I have created a directory and i would like to implement in pl/sql a procedure that return the list of files contained.
    Anybody know the general solution for this matter?
    Thanks in advance

    Tom Kyte has an example:
    Directory List including modify date and times

  • Reading List of Files in a Directory

    Hi,
    I'm looking for some reference or perhaps an example of how to get LabView to show the files that are in a directory so that the user can choose the appropriate one to load in the run. Right now, I'm running my program with certain specific files in the directory and the list of files written into the program.
    Thank you very much,
    Rob Hal

    I'm sure there are a number of example programs shipped with LV or that could be downloaded from the archives. Anyway, here is a quick example that read a directory content, fills a listbox, and display the selected file content as a string.
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Select file.vi ‏57 KB

  • List all files in a directory

    How can I list all the files in a directory which has folders and files as well? I just wanna files..
    File dataDir = new File("c:/data/);
    File[] listing = dataDir.listFiles();
    but it list the immediate no of folders in the data directory. Is there a way to get all the files in the subdirectories in data folder and excluding the folders?
    thanks!

    Iterate over the returned array, ignoring those whose isDirectory() returns true.
    Alternatively, you could call listFiles(fileNameFilter) instead, with an implementation of FileNameFilter which rejects File objects whose isDirectory() returns true.

  • Getting list of files from Unix directory inclding files frm sub-directries

    Hi All,
            I am trying to use Fm 'SUBST_GET_FILE_LIST'  and
    'RZL_READ_DIR_LOCAL' for getting a list of all files in a Unix directory including files from sub-directories.
    In the first case I am getting an Exception called 'Access Error'
    and when I use the 2nd FM, I am not getting any output.
    Is there a special way to use these FMs.
    Kindly help.
    Regds,
    Shweta

    [url http://java.sun.com/developer/JDCTechTips/2003/tt0122.html#1]READING FILES FROM JAVA ARCHIVES (JARS)

  • List all files in a directory in order of timestamp

    have files from directory displayed in an array of columns,using the list icon. however i would like them to be in order of aquisition or timestamp, rather then all 1, 10ns 20s etc.
    is there anyway to control the indexing with time stamping order?

    LabVIEW allows you to sort just about anything. All you have to do is create a cluster containing everything you want for a "record" and make an array of those clusters. In your case, you want to cluster the file name with its time stamp (how about last modification date?). The sort function (we call them functions or VIs, not icons) will order your array based on the order in which you clustered your elements.
    I whipped up a tiny example. Give it a directory path and run it. The output is a list of the filed in that folder sorted according to their time stamp.
    If you have some clear specifications for your whole application, consider hiring an Alliance Member (like us). You will end up with a most professional example of LabVIEW code t
    o learn from and tweak as you like.
    Alliance Members are here to help. We do this stuff every day.
    Daniel L. Press
    PrimeTest Corp.
    www.primetest.com
    Attachments:
    List_Files_by_Time.vi ‏21 KB

Maybe you are looking for

  • Line item only display after run RFSEPA01

    Hi expert, I set up all gl account with line item display but i need to block GL and run program RFSEPA01 so that line item will posted to BSIS table. Is this need to run every after new posting done in? As i run for one GL before with RFSEPA01 after

  • Can I reinstall mountain lion and do away with Mavericks

    Can I reinstall from aps mountian lion and do away with Mavericks? I do not like Mavericks at all.

  • RoboHelp project keeps crashing

    I have been working with a large RH project since December that is linked to a 600 page FM book. I haven't had any problems until last Tuesday (1/20). When I was trying to update the project, I received error messages regarding several FM files that

  • Relative linking between tables no longer supported?

    With the Numbers 3.1 update, relative linking between cells in different tables no longer seems to work. That means that if I want to pull the value of one cell into a cell in another table, now if I reorder either table, the value that gets passed c

  • Combined reports: activities and contact person related accounts

    Hello, I created a combined report that should show following things: Appointment data, all Related Users, all Related Contact Persons and the companies which are assigned to the Contact Persons (not the Appointment-related-Company!) I combined it by