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++;

Similar Messages

  • Bug with workflow that creates a folder and sub folder with the same name.

    Hi,
    I've found a possible bug in SharePoint 2010 workflows. I only have access to SharePoint 2010 and SharePoint Designer 2010 over my companies intranet, afaik I don't have access to to logs or anything server side so sorry for the any missing information.
    I had some problems with a workflow in one list that needed to create some folders and subfolders in a second list. The production version did a lot more so I setup a test area with 1 list and a workflow that only does the folder creation part and have managed
    to consistently replicate this problem.
    The test list has two columns, [title] and [sub folder title]
    The workflow starts by getting the values for [title] and [sub folder title] into variables.
    It then creates a folder in the same list with the same name as [title], and then creates a sub folder under this with the name from [sub folder title]
    So the resulting structure would be:
    Test List:-
        List item with fields [title] and [sub folder title]
        [folder: title]:-
            [folder: sub folder title]
    If both folder names are different (e.g Folder1 and Folder2) then it works perfectly fine, if both folder names are the same (regardless of character case, e.g. samefolderName and sameFolderName) then the workflow fails.
    As part of the test i made the first action of the workflow to log the message "Workflow Started" to the history list. When the workflow fail there's nothing logged in the history list other than the error: "The workflow could not update the
    item, possibly because one or more columns for the item require a different type of information."
    Creating a sub folder with the same name as it's parent works fine manually but for some reason a workflow can't seem to do it in one action.
    As there's no history list entries before the error it looks like the workflow is just failing to start but if i do something like add an if statement to check if [title] and [sub folder title] are the same, and only create the subfolder when they are not
    then it runs fine doing what it's set to.
    The function of the workflow in our office was for convenience so were just working without it. Just wanted to post to see if anyone else has come across this/could try to replicate or explain this  and see if it's a SharePoint bug or something specific
    to our setup.
    thanks,
    Martin

    not sure about the specifics of your workflow, but if you're querying the list for the folders... keep in mind that a list lookup will only ever bring back ONE item... even if there are several items that meet the filter criteria... example: if i search
    a list for an item assigned to "john doe", there may be 15 tasks that meet the criteria, and it'll only grab one... this is why SP Designer WARNS you when your list lookup may exhibit this behavior.
    Scott Brickey
    MCTS, MCPD, MCITP
    www.sbrickey.com
    Strategic Data Systems - for all your SharePoint needs

  • 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

  • Loop through the excel files in folder and sub folder

    hi all
    I need to loop  through all the excel fies in a folder and its sub folder which contain excel files 
    actually, my excel files contain a column  with sdate and it contain different dates in which  has to get the max  date my query is 
    "select * from  @[User::filename] where sdate=(select max(sdate) asi  from @[User::filename] )"
    loop  all the excel file in folder and its sub folder

    Take a look at the Foreach Loop.
    Here is an article about it.
    Andy Tauber
    Data Architect
    The Vancouver Clinic
    Website | LinkedIn
    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click
    "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.

  • Folder and Sub-Folder Batch load Script

    What I'm looking for I'm not ever sure is possible, but what I need is a script that will search for predefined sub-folder names within a specific "root" folder and run a script I have to load those images into a Photoshop document found within the root folder.  When loading these images, it will also need to place the images into a specific group within the Photoshop document, depending on the sub-folder that contained them.  So images in the sub-folder "A" need to be loaded into the group "A" in the Photoshop document, images in sub-folder "B" into group "B" and so-on.  The number and name of images within the sub-folders are, however, random; so this would also need to be accounted for.  Additionally, if possible, I would like the script to ask the user to locate this root folder each time before proceeding; otherwise, if not possible, a static folder location can also be used.  Thanks for any help!
    dgolberg

    Profile-mismatches as in: When the container document and the image to be placed are of different Color Spaces (different ICC-profiles).
    Could you give this a try (on a copy of your files naturally); it places as Smart Objects (depending on your Photoshop > Preferences > General settings), but you could always rasterize after the import or chenge the preference in the Scripts and reset it at the end:
    // place png-files from a folder and its contained folders with groups to represent those in jpg-files;
    // 2011, use it at your own risk;
    #target photoshop
    // select folder;
    var theFolder = Folder.selectDialog ("select folder");
    if (theFolder) {
    // get the jpgs;
    var theJpgs = getJpgFiles(theFolder);
    // iterate through the jpg files;
    for (var m = 0; m < theJpgs.length; m++) {
    var theDoc = app.open(new File(theJpgs[m]));
    // thanks to xbytor;
    var theName = theDoc.name.match(/(.*)\.[^\.]+$/)[1];
    // place the png-files in groups coresponding to the folders;
    placeFolderFiles(theFolder, theDoc, theName)
    ////// ceck for jpgs //////
    function checkJpg (theFile) {
        if (theFile.name.match(/\.(jpg)$/i)) {
            return true
    ////// ceck for pngs //////
    function checkPng (theFile) {
        if (theFile.name.match(/\.(png)$/i)) {
            return true
    ////// place //////
    function placeScaleFile (file, xOffset, yOffset, theScale) {
    // =======================================================
    var idPlc = charIDToTypeID( "Plc " );
        var desc5 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
        desc5.putPath( idnull, new File( file ) );
        var idFTcs = charIDToTypeID( "FTcs" );
        var idQCSt = charIDToTypeID( "QCSt" );
        var idQcsa = charIDToTypeID( "Qcsa" );
        desc5.putEnumerated( idFTcs, idQCSt, idQcsa );
        var idOfst = charIDToTypeID( "Ofst" );
            var desc6 = new ActionDescriptor();
            var idHrzn = charIDToTypeID( "Hrzn" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc6.putUnitDouble( idHrzn, idPxl, xOffset );
            var idVrtc = charIDToTypeID( "Vrtc" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc6.putUnitDouble( idVrtc, idPxl, yOffset );
        var idOfst = charIDToTypeID( "Ofst" );
        desc5.putObject( idOfst, idOfst, desc6 );
        var idWdth = charIDToTypeID( "Wdth" );
        var idPrc = charIDToTypeID( "#Prc" );
        desc5.putUnitDouble( idWdth, idPrc, theScale );
        var idHght = charIDToTypeID( "Hght" );
        var idPrc = charIDToTypeID( "#Prc" );
        desc5.putUnitDouble( idHght, idPrc, theScale );
        var idLnkd = charIDToTypeID( "Lnkd" );
        desc5.putBoolean( idLnkd, true );
    executeAction( idPlc, desc5, DialogModes.NO );
    return app.activeDocument.activeLayer;
    ////// place images in folder and contained folders //////
    function placeFolderFiles (theFolder, theContainer, theName) {
              var theContent = theFolder.getFiles();
              for (var n = theContent.length - 1; n >= 0; n--) {
                        var theObject = theContent[n];
                        if (theObject.constructor.name == "Folder") {
                                  var aFolder = theContainer.layerSets.add();
                                  aFolder.name = Folder(theContent[n]).name;
                                  placeFolderFiles(theObject, aFolder, theName)
                        if (checkPng(theObject) == true && theObject.name.match(theName)) {
                                  var theLayer = placeScaleFile(theObject, 0, 0, 100);
                                  theLayer.name = File(theObject).name;
                                  theLayer.move(theContainer, ElementPlacement.PLACEATBEGINNING)
    ////// place images in folder and contained folders //////
    function getJpgFiles (theFolder) {
              if (!theArray) {var theArray = new Array};
              var theContent = theFolder.getFiles();
              for (var n = theContent.length - 1; n >= 0; n--) {
                        var theObject = theContent[n];
                        if (theObject.constructor.name == "Folder") {
                                  theArray = theArray.concat(getJpgFiles(theObject))
                        if (checkJpg(theObject) == true) {
                                  theArray.push(theObject)
              return theArray

  • Automating Group, Sub Group, Folder and Sub Folder Creation

    I am relatively new as an administrator, and this may be a simple question.
    I need to publish similar groups and folders for 30 instances. I am able to complete this through the CMS functionality, but I was wondering if there was some form of command line input or SQL statement I could use to add them instead. Automation of this process would provide a great time savings, so I am wondering if such a command line/batch file/SQL statement exist. My instance of Business Objects is run with A CMS attached to an Oracle database (if the SQL statement proves to be the answer).
    Thanks in advance for any assistance that can be provided.

    There is no simple command line utility to do this. This is possible via the Enterprise SDK though ([here|http://devlibrary.businessobjects.com/BusinessObjectsXIR2/en/devsuite.htm])

  • Can I import an entire folder and sub-folders at once?

    I am fairly new to LR and have TONS of files in a main Photo folder on Vista.  Some of these files have duplicate names, some were taken with very early gen digital camera as well as newer files with my 40D. But importing each folder and sub folder 1 at a time is going to take a million years.  Here is basically what I want to do.
    1) Import ALL pics (probably about 6-8 thousand) at once
    2) Go through these photos and tag them as well as get rid of the obviously crappy pics that i will never do anything with, kill the dupes
    3) Meta tag as many as i can
    4) export to a new foler
    All files are jpg.  Nice memorial day project eh?

    I would make some suggestions to your proposed workflow.
    Instead of "3) Meta tag as many as i can", I would say assign keywords and captions on all of your photos. Keywords and captions are a very powerful way of organizing, and when well done, they make finding your photos extremely easy. I understand that this takes time and effort, but you will find that the time and effort you put into this pays off well.
    If you leave some photos without keywords and captions, how will you find them? I know how ... you will search for 30 minutes and probably say some four-letter words in the process.
    Instead of "4) export to a new foler[sic]", don't bother exporting as a regular part of your workflow. Just don't do it! Only export when you need the photos outside of Lightroom, such as for e-mail or uploading or printing at a commercial printer. Otherwise, there is no need for you to take up the disk space with thousands of exported .jpgs.

  • 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

  • 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

  • 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

  • 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

  • 'Contacts' folder with sub folder cannot be removed after synching via iTunes

    'Contacts' folder with sub folder cannot be removed after synching via iTunes
    I am trying to remove a 'Contacts' subfolder
    ie Contacts < default folder
    - Contacts Mysubfolder 1 < Trying to remove this subfolder folder
    via my microsoft outlook onto my iPhone.
    Despite not having 'Contacts Mysubfolder 1' on my PC's outlook after deleting it, it does not delete the subfolder in my iPhone.
    I even restored my iPhone settings to the original via iTunes.
    I also replaced my physical iPhone but still synching with my original Apple ID + iTunes on the same desktop.
    All I did was after replacement of my iP, i setup my microsoft Exchange account, and there it was, the Contacts subfolder which is no longer around, appears on my iPhone contacts folder list.
    My outlook is on Microsoft exchange and I am on iP 3Gs
    Please help
    Thank you

    For general advice see Troubleshooting issues with iTunes for Windows updates.
    The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down the page in case one of them applies.
    Your library should be unaffected by these steps but there is backup and recovery advice elsewhere in the user tip.
    If you are running 64-bit Windows and the above steps haven't helped try installing the version of iTunes that can be downloaded from this support document. iTunes 12.1 for Windows (64-bit — for older video cards)
    If you still have no luck try reinstalling iTunes 12.0, links in the user tip.
    tt2

  • What would be the difference between sling:folder and nt:folder?

    what would be the difference between sling:folder and nt:folder?

    See,
       As Nicolas said, there are some things that you can do only in a sling:folder type of node.
       The "nt" means "Node Type", and a "node type: folder" is just a empty node that can be referenced as a organizational structure file folder. The "sling" prefix means that this one special folder belong to the type "Sling", in other words, that folder type node is built in the sling Framework structure and is constructed with some setting already, which I do not know to tell you. Take a look at "/libs/sling/nodetypes/sling.cnd" on you CRXDE Lite or CRXDE.
    (I may be wrong about some details, eveything here is what I believe myself after some research and experience)

  • I want to know the difference between iphoto master folder and previews folder

    I want to know the difference between iphoto library master folder and previews folder.. my pictures is stored in master but part of them is also copied into previews.. it occupied too much space.. if I can't change anything in iphoto library, any way to save the space for iphoto? 70G for almost 15,000 pictures, is it reasonable?
    i use mac book pro, ilife 11..

    70GB for 15,000 photos is reasonable, yes, if the photo files are large.
    DO NOT meddle with the contents of your iPhoto Library in any other way than using the commands available in the iPhoto application. What appear to be duplicate files stored in different parts of the library are NOT duplicates, and if you attempt to save space by deleting things in the Finder, you will wreck your library and land in a world of trouble.

  • 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

Maybe you are looking for

  • I don't know where to put this so here it is

    No problem with Safari, but I also use Firefox and successfully for 2 years to do my portfolio on Yahoo Finance. Yesterday, when I clicked on my portfolio in Firefox, it suddenly started downloading -DARTIframe.html (it appears in MacSource)- . I cou

  • Touchscreen Monitor for MacBook Pro

    I just bought a 15" Macbook Pro with Parallels 9 and Windows 8.  Can anyone recommend a touch screen monitor that I can use with my new workstation?  I would like to get rid of my Dell desktop and just use the Macbook Pro for both desktop and laptop

  • Address book missing in New Message Window

    Although I can append the Address Book icon to the toolbar in the main Mail window, this is not acessable from the New Message Window.  I have several email accounts and prefer to not use the auto-complete tool in Mail.  However, I'd rather not have

  • How do I install my education version of CS5 photoshop extended using the CD I purchased ?

    How do I install my education version of cs5 photoshop extended using the CD I purchased ?  I slid it into the side slot of my computer and nothing comes up on the screen.  I'm not sure where to go from here.....

  • Help, Adobe Designer 7.0 Debug Error!

    Come with Adobe Acrobat 7.0 Pro on Windows XP machine P4 3.2GHz RAM 512Mb another s/w is Borland delhi 6.0 When I Select File -> New and the new form appears. then select field object (text, numeric, etc) in the library palette. I got: Microsoft Visu