Read all files in chield and their chield's directory

I am trying to make a program which read all files in a directory and its subdirectory like scandisk program of window's operating system. I gause this I can do via recursion using the methods isDirectory(), File.list() etc. Please help me to implement this problem in code.
Regards
yogesh

you guys should collaborate,
http://forum.java.sun.com/thread.jsp?forum=4&thread=153110&start=0&range=30#443719

Similar Messages

  • Read All files in folder and sub folder

    Hi,
    i can read files in a folder,but not in a sub folders.can any one give me idea to read all files in the folder and its sub folder.
    Deepan

    Hi
    This code may help you
    Bliz
    import java.io.File;
    import java.io.IOException;
    import java.io.RandomAccessFile;
    import java.nio.channels.FileChannel;
    public class CountFiles {
          * @param args
          * @throws IOException
          * Count files in <path> and all its subDirs
         public static String path = "c:";
         public static String src1 = "";
         public static FileChannel channel;
         public static int numF;
         public static int numD;
         public static void main(String[] args) throws IOException {
              countFiles(path);
              System.out.println("Number of files :\t"+numF);
              System.out.println("Number of dirs :\t"+numD);
         public static void countFiles(String strPath) throws IOException
              File src = new File(strPath);
              if (src.isDirectory())
                   numD++;
                   String list[] = src.list();
                   try {
                       for (int i = 0; i < list.length; i++)
                        src1 = src.getAbsolutePath() + "\\" + list;
                        File file = new File(src1);
                        try {
                   channel = new RandomAccessFile(file, "r").getChannel();
                        }catch(java.io.FileNotFoundException e){}
                        countFiles(src1);
                   }catch(java.lang.NullPointerException e){}
              else
              numF++;

  • Newbie question -  How to read all files for a backup

    Hello all,
    I have two users on my iMac. I am an administrator and the other user is a Standard user.
    From my account, I wish to run backup software that will backup the entire "User" directory. The problem I am having is that when I run the backup software (fyi: iBackup),
    it complains that it cannot read the files in the other user's account.
    I notice that when I browse to the other user's account, all the directories in their home folder are locked.
    How can I run my backup software so that it can read all files in the User directory?
    Thank you kindly!
    Jeff
    17" iMac Core Duo   Mac OS X (10.4.6)  

    Hi kneecarrot !
    I don't know if this will suit your needs, but one easy way of backing up other user's stuff is via the terminal . If you have an admin accountm just use:
    sudo ditto -rsrcFork /Users /Volumes/"nameof_anotherharddrive"/Users
    This will perform an identical clone of all your users home direcories for backup purposes. To restore the bkd'up files, just reverse the lines:
    sudo ditto -rsrcFork /Volumes/"nameof_anotherharddrive"/Users /Users
    ATTENTION: Be aware that it will restore the files to the exact structure and contents it was when backed up, erasing all new and modified files!! You may however copy just the files/folders you want to recover, e.g.:
    sudo ditto -rsrcFork /Volumes/"nameof_another_harddrive"/Users/"usera"/Documents /Users/"user_a"/Documents
    IMPORTANT: As with all terminal commands... be careful, think twice and double-check the syntax. You may want to test with non-critical stuff or demo user accounts first.
    Good luck,
    Michael
    MacBook Pro   Mac OS X (10.4.6)   2 Gig RAM

  • How to Read all files inside resource Folder inside Jar?

    I have a Jar file,,,, The program reads for resource files in the resource folder inside the Jar. I want my program to read all files inside this folder without knowing the names or the number of files in the folder.
    I am using this to make an Applet easy to be updated with spicific files. I just want to add a file inside the resource folder and Jar the program and automatically the program reads what ever is in there!!
    I used the File class to get all file names inside the resource folder. it works fine before Jarring the program. After I jar I recieve a URI not Herarichy Exception!!
    File fold=new java.io.File(getClass().getResource(folder).toURI());
    String[] files=fold.list();
    I hope the question is clear!!

    How to get the directory and jar file that you class resides in:
    // returns path and jarfile (ex: /home/mydir/my.jar)
    public String getJarfileName()
            // Get the location of the jar file and the jar file name
            java.net.URL outputURL = YourClass.class.getProtectionDomain().getCodeSource().getLocation();
            String outputString = outputURL.toString();
            String[] parseString;
            int index1 = outputString.indexOf(":");
            int index2 = outputString.lastIndexOf(":");
            if (index1!=index2) // Windows/DOS uses C: naming convention
               parseString = outputString.split("file:/");
            else
               parseString = outputString.split("file:");
            String jarFilename = parseString[1];
           return jarFilename;
    }If your my.jar was in /home/mydir, it will store "/home/mydir/my.jar" in jarFilename.
    note: getLocation returns "file:/C:/home/mydir/my.jar" for Windows/DOS and "file:/home/mydir/my.jar" for windows, thus why I look for the first and last index of the colon so I can correctly split the string.
    If you want to grab a file in the jar file and get an InputStream, do the following:
    import java.io.*;
    import java.util.Enumeration;
    // jar stuff
    import java.util.jar.*;
    import java.util.zip.ZipEntry;
    public class Jaris
       private JarFile jf;
       public Jaris(String jarFilename) throws Exception
           try
                           jf = new JarFile(jarFilename);
           catch (Exception e)
                jf=null;
                throw(e);
       public InputStream getInputStream(String matchString) throws Exception
           ZipEntry ze=null;
           try
              Enumeration resources = jf.entries();
              while ( resources.hasMoreElements() )
                 JarEntry je = (JarEntry) resources.nextElement();
                 // find a file that matches this string from anywhere in my jar file
                 if ( je.getName().matches(".*\\"+matchString) )
                    String filename=je.getName();
                    ze=jf.getEntry(filename);
          catch (Exception e)
             throw(e);
          InputStream is = jf.getInputStream(ze);
          return is;
       // for testing the Jaris methods
       public static void main(String[] args)
          try
               String jarFilename=getJarfileName();
               Jaris jis = new Jaris(jarFilename); // this is the string we got from the other method listed above
               InputStream is=jis.getInputStream("myfile.txt"); // can be used for xml, xsl, etc
          catch (Exception e)
             // this is just a test, so we'll ignore the exception
    }Happy coding! :)
    Doc

  • How  to read all files  under a folder directory in FTP site

    Hi Experts,
    I use this SQL to read data from a file in FTP site. utl_file.fopen('ORALOAD', file_name,'r');
    But this need to fixed file name in a directory. However, client generate output file with auto finename.
    SO do we have any way to read all file by utl_file.fopen('ORALOAD', file_name,'r');
    We need to read all file info. because client claim for security issue and does not to overwirte output file name,
    we must find a way to read all file in output directory.
    Thanks for help!!!
    Jim

    If you use Chris Poole's XUTL_FTL package, I believe that contains functions that allows you to query the directory contents.
    http://www.chrispoole.co.uk/apps/xutlftp.htm
    Edited by: BluShadow on Jan 13, 2009 1:54 PM
    misread the original post

  • Reading all files on directory using "utl_file" package...

    I need to read all files in directory via PL/SQL. I don't know
    name files (are data dynamics create for automation system),
    only I know your extensions.
    Can I do this using the package "utl_file" or I need to create
    program in another language (C, C++, for example)?
    Any ideas...
    Thanks.

    Hi,
    you can't do that with the UTL_FILE package (it can't retrieve
    file names).
    A very simple solution would be, if you created on OS-level a
    file which contains the filenames of directory and then read this
    file using UTL_FILE. With the information on all file names you
    can enter a loop which opens and reads all files again using
    UTL_FILE.
    A more mundane solution could be to use the features on the iFS.
    Cheers
    Gerald

  • File Adapter - Reading 2 files from sender and one file to receiver

    All - I am looking for a best solution for reading two files from sender and generating one file to the receiver.
    Here is the scenario
    Sender file s - A is a master file. B is a detail file; B will have a one to many records for each record of File A.. that is the relation ship between 2 files..  I am looking for a better solution to
    Example
    Input:
    File A will have a record like "summary1 ABC 1234"
    File B will have a record like "Detailfor Summary1 CDF 8679"
    Output:
    File C shall have a record "consolidatedofSummary&Detail ABC 1234 8679"
    1) read records of master row and detail row from these 2 files
    2) do the mapping to the receiver output format which it is creating for records with some harcoded values and based on the values from master and detail rows of sender file
    if I can accomblish reading sender files and do the mapping to the receiver , assume that mapping to the receiver format would not be cumbersome.
    please help me...
    Thanks

    Hi Gopal,
    Ur approach to the interface is perfect.... Go ahead.
    For selecting multiple files in source use Advanced Selection for files.. and specify the directory paths and also the file name shema...
    This will fetch the 2 files into the integration engine... then u map the 2 source files to one target file(2:1 mapping).
    Specify accordingly the receiver side FCC and test it end to end...
    If u face any prblm post here... some1 will help u out..
    Babu

  • Where to see all available function modules and their purposes.

    Dear all Experts,
    Can anybody please tell  where i will be able to see the all availble function modules, and their purpose....
    eg, if i have to retrive data from my pc file (.txt or .xls) , using GUI_UPLOAD, then i have to take file name in form of string.
    to take that from user, in form of string, we use function  <b>'KD_GET_FILENAME_ON_F4'</b>..
    can anybody give related links ?
    your help will be certainly rewarded.
    waiting
    Regards
    Vinay...............

    Hi Vinay..
    just go through these links
    you can find lot of information which u need
    this is having the Function module names and the Description and the use of that function module
    http://www.erpgenie.com/abap/functions.htm
    http://www.geocities.com/victorav15/sapr3/abapfun.html
    http://www.onestopsap.com/function-module/
    http://www.sapdevelopment.co.uk/fmodules/fmssap.htm
    Regards Rk

  • Query to find all the view name and their size in GB

    Hi,
    What is the query to find all the view name and their size in GB.I am aware of joining all_views and user_segments but this is not serving the purpose.is there any table i need to join to get the desired result
    Thanks

    You could of course be thinking of views as they are stored in other RDBMS' as some of them actually create the view as a table on the database with a copy of the data in it and maintain that data as the base tables are updated.
    As already mentioned, Oracle just stores the SQL of the View and executes that SQL when the view is queried.
    Alternatively, Oracle also has "materialized views" which are created as snapshots of the data and will have a size. This data is updated (refreshed) based on the parameters used when creating the materialized view which means that it will either be, commonly, when a commit is issued or when a refresh is explicitly requested (refresh on demand).

  • Read from file, compare string and return a part

    Hello, is there a reasonable good way to read text file containing information, and if string comparison is successfull, return a nother part of the string.
    What i have done so far:
    set file_name to (path to desktop as text) & "filename.txt"
    set F to open for access tiedosto with write permission
    set file_information to (read F)
    close access F
    (i will be moving this to Application Support/Appname/ when i figure it out).
    The data in the file is in following format
    12234567890Name1
    98765432123Name2
    92347928347Name3
    What im stuck now is:
    I need to compare each line the 10 numbers with search string, if match is found, the name part should be returned.
    Any idea's?

    You already read in the text file, so you need to put the data thru a repeat loop:
    repeat with name_part in paragraphs of file_information
    -- ((character 1 thru 10 of name_part) as string) is the first 10 digits of name part
    if ((character 1 thru 10 of name_part) as string) is search_string then return name_part
    end

  • Read all Files from a Folder on Server

    Hi,
    Can anyone help me in finding if there's any way to read all files in a folder on the server?Any Function module or anything.
    Thanks

    On App server?  Try this sample program.
    report zrich_0001 .
    data: begin of itab occurs 0,
          rec(1000) type c,
          end of itab.
    data: wa(1000) type c.
    data: p_file type localfile.
    data: ifile type table of  salfldir with header line.
    parameters: p_path type salfile-longname
                        default '/usr/sap/TST/DVEBMGS01/data/'.
    call function 'RZL_READ_DIR_LOCAL'
         exporting
              name           = p_path
         tables
              file_tbl       = ifile
         exceptions
              argument_error = 1
              not_found      = 2
              others         = 3.
    loop at ifile.
      format hotspot on.
      write:/ ifile-name.
      hide ifile-name.
      format hotspot off.
    endloop.
    at line-selection.
      concatenate p_path ifile-name into p_file.
      clear itab.  refresh itab.
      open dataset p_file for input in text mode.
      if sy-subrc = 0.
        do.
          read dataset p_file into wa.
          if sy-subrc <> 0.
            exit.
          endif.
          itab-rec = wa.
          append itab.
        enddo.
      endif.
      close dataset p_file.
      loop at itab.
        write:/ itab.
      endloop.
    Regards,
    Rich Heilman

  • I cannot get subtitles on my new smart tv. I've read all the solutions online and none of them work. When I try to airplay the BBC i player by mirroring my iphone 4 the subtitles disappear when I change from iphone to appletv.

    I cannot get subtitles on my new smart tv. I've read all the solutions online and none of them work. When I try to airplay the BBC i player by mirroring my iphone 4 the subtitles disappear when I change from iphone to apple tv.

    That's because the BBC iPlayer app uses basic AirPlay to show the content, this means the original content is sent to the Apple TV for it to decode rather than mirroring the screen of the iPad where the subtitles are added.

  • HTML  Parsers and reading all files in a directory

    Hello all,
    I was wondering if there was a html parser included in java. I am writing a program where I want to be able to search all the files in a directory tree for a particular string. I was able to read one file in a single directory but not in any other directory. How would I go about writing code to be able to access all files in directory that has multiple sub folders.
    Also, when I started to write my program I tried to use the DOM XML Parser to parse my html page. My logic behind this decision was that if you look at html code it is an xml document. But as I was trying to run my program I noticed that I had to convert my html document into xml format. I really don't want to have to build my own html parser. Is there a html parser that is included in Java. Oh my program is just your basic text program. No interfaces.
    Thanks for any help that you can provide
    Hockeyfan

    a particular string. I was able to read one file in
    a single directory but not in any other directory.
    How would I go about writing code to be able to
    access all files in directory that has multiple sub
    folders.
    You can do that several ways.
    Most likely you'll end up with some sort of recursive iteration over the directory tree.
    Not hard to write, somewhat harder to prevent memory problems if you end up with a lot of data.
    Also, when I started to write my program I tried to
    use the DOM XML Parser to parse my html page. My
    logic behind this decision was that if you look at
    html code it is an xml document. But as I was
    trying to run my program I noticed that I had to
    convert my html document into xml format. I really
    don't want to have to build my own html parser. Is
    there a html parser that is included in Java. Oh my
    program is just your basic text program. No
    interfaces.
    A VALID xhtml document is a valid XML document.
    Problem is that most HTML isn't xhtml.
    Another problem is that most HTML is fundamentally broken even to its own standards (which have always been based on SGML on which XML is also based).
    Browsers take that into account by being extremely lax on standards compliance and effectively making up tags as they go along to fill in the missing ones in the trees they parse.
    That's however not a standardised process and each browser handles it differently (and as a result most html will render differently in different browsers).
    Java contains a simple HTML parser in Swing, but it's primitive and will only parse a subset of HTML 2.0.
    There are almost certainly 3rd party libraries out there that can do better, both free and/or commercial.

  • Reading All Files inside folder codeBase, Applet!

    I have an applet, placed in a Jar file.. everything is ok,,
    I have a resource folder outside the Jar, which has some files.
    how can I read what is inside the resource folder, which is located outisde the Jar, without having their addresses before hand!!
    in short, I would like the applet to open the resource folder, get an array of all files in the folder, and then reads them.
    I tried encapsulating the getCodeBase().toURI() with a File Object.
    But when I call the file.list() it throws an AccessControlException
    thank you.

    Here is a simple example of using ftp to obtain file list using Jakarta common net package.
    // ftp - related imports
    import org.apache.commons.net.ftp.FTPClient;
    import org.apache.commons.net.ftp.FTPReply;
    // main method
              FTPClient ftpClient = null;
              try {
                   ftpClient = new FTPClient();
                   ftpClient.connect("REMOTE_HOST", "remote port, use 21 in common case");
                   System.out.print(ftpClient.getReplyString());
                   int reply = ftpClient.getReplyCode();
                   if(!FTPReply.isPositiveCompletion(reply)) {
              ftpClient.disconnect();
              System.err.println("FTP server refused connection.");
              System.exit(1);
                   boolean isLoggedIn = ftpClient.login("your login", "your pass");
                   ftpClient.changeWorkingDirectory("/your remote dir/");
                   String[] fNames = ftpClient.listNames();
                   for (int i = 0; i < fNames.length; i++) {
                        System.out.println(fNames);
                   ftpClient.logout();
              } catch (IOException e) {
                   e.printStackTrace();
              } finally {
                   if(ftpClient.isConnected()) {
                        try {
                             ftpClient.disconnect();
                        } catch(IOException ioe) {
                             ioe.printStackTrace();
    System.exit(0);

  • Read All Files in a Folder

    I have a large set of data. Many don't have similar names at all. They
    all have the same data form (a 100x2 array for example).
    Is there a way to have a VI read all the files, one after another,
    automatically? It's a lot easier when the files are the same name, but
    ending/starting with different ID numbers. If they're all different,
    what can I do?
    Also, is it possible to create a VI, so that a file 'dropped' onto the
    VI's icon, will cause it to process the data? I'm not sure if this is
    a Labview or MS Windows problem.
    Thank you for your time.
    -Dorian
    [email protected]
    Please post if possible, to share.

    Dorian;
    You can simplify this if all your files are in the same directory. Check the example attached that read all .jpg images in a directory and display them in a picture control. Enter the directory path before running.
    As for your second question, it can be done, but I think (I might be wrong) that you must convert your vi into an executable. Check the following example:
    Get Calling File Path from Command Line
    Best regards;
    Enrique
    www.vartortech.com
    Attachments:
    image_show.vi ‏24 KB

Maybe you are looking for