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.

Similar Messages

  • 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

  • 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

  • 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

  • How to list all files and directories in another directory

    I need to be able to list all the directories and files in a directory. I need to write a servlet that allows me to create an html page that has a list of files in that directory and also list all the directories. That list of files will be put into an applet tag as a parameter for an applet that I have already written. I am assuming that reading directories/files recursively on a web server will be the same as reading directories/files on a local system, but I don't know how to do that either.

    Hi,
    Here is a method to rotate through a directory and put all the files into a Vector (files).
          * Iterates throught the files in the root file / directory that is passed
          * as a parameter. The files are loaded into a <code>Vector</code> for
          * processing later.
          * @param file the root directory or the file
          *         that you wish to have inspected.
         public void loadFiles(File file) {
              if (file.isDirectory()) {
                   File[] entry= file.listFiles();
                   for (int i= 0; i < entry.length; i++) {
                        if (entry.isFile()) {
                             //Add the file to the list
                             files.add(entry[i]);
                        } else {
                             if (entry[i].isDirectory()) {
                                  //Iterate over the entries again
                                  loadFiles(entry[i]);
              } else {
                   if (file.isFile()) {
                        //Add the file
                        files.add(file);
    See ya
    Michael

  • How to get all files in one directory

    Hi there,
    is there any way to get all the files in one directory?
    e.g. a method
    File[] getAllFiles(String directory){
    Thank you

    Just out of interest, which part of the File API was confusing?
    http://java.sun.com/j2se/1.5.0/docs/api/index.html
    If you look down the left-hand side, you'll see a frame listing "All File". If you select "File" from that list, it opens up the API in the right-hand frame. Quite near the top you'll find "listFiles".
    I only ask as this (and other questions easily answered by looking at the API) are frequently asked. Did you overlook it when you read the API or did you just not read it?
    I really want to know. I think there is scope to cater for that behaviour within this site. A nice API finder would be good; something more intelligent than the search function (which people use less frequently even than the API docs).

  • How can I create a array with all files from a directory

    How can I create a array of files or varchar with all files from a directory?

    I thought the example could be improved upon. I've posted a solution on my blog that doesn't require writing the directory list to a table. It simply returns it as a nested table of files as a SQL datatype. You can find it here:
    http://maclochlainn.wordpress.com/2008/06/05/how-you-can-read-an-external-directory-list-from-sql/

  • 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

  • How to get the file size (in bytes) for all files in a directory?

    How to get the file size (in bytes) for all files in a directory?
    The following code does not work. isFile() does NOT recognize files as files but only as directories. Why?
    Furthermore the size is not retrieved correctly.
    How do I have to code it otherwise? Is there a way of not converting f-to-string-to-File again but iterate over all file objects instead?
    Thank you
    Peter
    java.io.File f = new java.io.File("D:/todo/");
    files = f.list();
    for (int i = 0; i < files.length; i++) {
    System.out.println("fn=" + files);
    if (new File(files[i]).isFile())
         System.out.println("file[" + i + "]=" + files[i] + " size=" + (new File(files[i])).length() ); }

    pstein wrote:
    ...The following code does not work. Work?! It does not even compile! Please consider posting code in the form of an SSCCE in future.
    Here is an SSCCE.
    import java.io.File;
    class ListFiles {
        public static void main(String[] args) {
            java.io.File f = new java.io.File("/media/disk");
            // provides only the file names, not the path/name!
            //String[] files = f.list();
            File[] files = f.listFiles();
            for (int i = 0; i < files.length; i++) {
                System.out.println("fn=" + files);
    if (files[i].isFile()) {
    System.out.println(
    "file[" +
    i +
    "]=" +
    files[i] +
    " size=" +
    (files[i]).length() );
    }Edit 1:
    Also, in future, when posting code, code snippets, HTML/XML or input/output, please use the code tags to retain the indentation and formatting.   To do that, select the code and click the CODE button seen on the Plain Text tab of the message posting form.  It took me longer to clean up that code and turn it into an SSCCE, than it took to +solve the problem.+
    Edited by: AndrewThompson64 on Jul 21, 2009 8:47 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Database query in MaxL DBS-Name list all file information failed

    When I tried list all file information command in MaxL it gave me an error saying the user doesn't exist. When I check the user through display user; command in MaxL I get the information as listed below.
    Is there something wrong with the way the user was created ?
    How can I (Admin) get the index and data file information?
    MAXL> query database Application.Database list all file information;
       ERROR - 1051012 - User ADMIN@Native Directory does not exist.
    MAXL> display user;
    user                description         logged in           password_reset_days enabled             change_password     type                protocol
       conn param          application_access_
    +-------------------+-------------------+-------------------+-------------------+-------------------+-------------------+-------------------+-----------------
    --+-------------------+-------------------
    ADMIN@Nati                                    TRUE                   0                TRUE               FALSE                   3 CSS
       native://DN=cn=911,                   1

    Has anyone resolved the problems with using TNSFormat?
    As is, I want to move to a shared server setup and to do that I want to use TNSFormat and point to a tns entry which is setup for IPC+Shared connection.
    But the Oracle Home that has the Oracle HTTP Server (from the companion CD) does not have SQL*net installed and does not seem to understand TNS.
    I have TNS_ADMIN setup, I have ORACLE_HOME_LISTENER poiting to the DB Home.
    for the OHS home, using "sqlplus login/pw@ipcshared" works, but "tnsping ipcshared" does not, since tnsping does not exist in the OHS home.
    I cannot install SQL*Net from the CD1, since it requires a dedicated/new home and does not want to install in the OHS Home.
    The only format that works in a dedicated OHS Home setup is ServiceNameFormat.
    Any help or input would be very helpful.
    Regards
    ps. This is a redhat linux setup.
    Message was edited by:
    Oli_t

  • 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

  • How to list all files in my system

    Hi there,
    I want to list all files in my system. My system is Windows XP, can anybody help me please? Any can you recommend me if java is suit for such processing?
    Thx in advance.

    public void showFilesIn(File dir) {
        File[] files = dir.listFiles();
        for (int i = 0 ; i < files.length ; i++)
            if (files.isDirectory())
    showFilesIn(files[i]);
    else
    System.out.println(files[i]);
    showFilesIn(new File("C:\\"));
    notice that it won't show directories, but only files

  • 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 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

  • Finder not displaying all files in remote directory

    Sorry, this is a repost as I have gotten no response from my original request here: Finder not displaying all files in remote directory
    I've exported pictures from iPhoto on my iMac to a shared directory on my mac mini. When I access that directory from my iMac, I can see some but not all of the pictures. I know the pictures exported properly because I can see them all from the mac mini. I can open up a terminal window on my iMac and see all of the files; I can also open those files from the terminal.
    I'm running OSX 10.9.4 on both computers, with the mac mini also running OSX Server. I've placed a screen grab below from my iMac of what Finder sees vs what I can see from the terminal.
    Why isn't Finder displaying all of my files?

    thanks for responding
    Adding a new file to the shared folder results in me being able to see the new file from my clients regardless of where it was added from, however the "hidden" files do not suddenly pop up.
    I tried a few more experiments that had interesting results, but still didn't lead me to an answer.
    First I tried copying the files from the remote directory to a local directory; I did this in 2 different ways and had different results. Method A) I copied files from the mounted share to a local dir: "cp /Volumes/MyShare/dir/*.JPG .". Method B) I copied the files using secure copy: "scp user@server:/path/to/dir/*.JPG .".
    Method A resulted in Finder not being able to see the files in the local directory, while Method B did. This was interesting and lead me to suspect an issue with the way I am sharing the directory on the server. From Server settings I have both afp and smb checked. I tried enabling only one or the other and reconnecting; but this did not fix the problem.
    Next I tried exporting the photos from iPhoto again. Exporting them locally results in files that Finder can see. Exporting them to my server results the same bad behavior
    Getting desperate, I also tried renaming all of the files from "*.JPG" to "*.jpg" but this didn't help.
    One last experiment, I see the same behavior from both another Mac and a PC on my local network... FTP works fine.
    Any more ideas?

Maybe you are looking for

  • 'Out of Range' message

    Newbie here, so apologies if this problem has been raised a million times. I have a BT line and a BT Stratus phone/answering machine. I have been having problems with my phone fading out on me, so I replaced the rechargeable batteries, but the same '

  • What is a good project management app for the iphonee

    I am looking for a good project management app for an ip4. I need it for planning and costing landscape projects many thanks leon

  • Reconcilition account in MIRO

    I had maintain alternate reconcilition account "1000002" for a reconcilitaion account "1000001" . now i am doing MIRO for a vendor to which reconcilitaion account "1000001" is maintain in vendor master. In detail tab in MIRO this reconcilitaion accou

  • Disable Checkbox "Print price" in a PO

    Hi experts! I am currently printing forms correctly in my system using form MEDRUCK. At the moment it is printing the prices automatically, because in tab "Condition Control" the checkbox "Print price" is activated. Is there any way to make this chec

  • Unit of measure KG to ST?

    Hi All, I have on ematerial initially created with unit of measuer KG by mistake, it was really supposed to be ST. Is there any way? Thank You.