Programatically count the number of files in a folder

Hi Folks
I need to programatically count the number of files in a given folder and return the value to a Program Unit to be included in further processing.
Can anyone point me in the right direction. I have looked at UTL_FILE but this does not offer what I want.
Does anyone know of an obscure package in Oracle that I could use?
I'm using 9i in a W2K environment.
Many thanks
Simon Gadd

Hi,
following a java based solution i found somewhere on Tom Kyte's AskTom forum.
GRANT JAVAUSERPRIV to TESTUSER;
dbms_java.grant_permission( 'TESTUSER', 'SYS:java.io.FilePermission', 'c:\', 'read' );
create global temporary table DIR_LIST
( filename varchar2(255) )
on commit delete rows
create or replace and compile java source named "DirList"
as
  import java.io.*;
  import java.sql.*;
  public class DirList
    public static void getList(String directory)
                       throws SQLException
      File path = new File( directory );
      String[] list = path.list();
      String element;
      for(int i = 0; i < list.length; i++)
          element = list;
#sql { INSERT INTO DIR_LIST (FILENAME)
VALUES (:element) };
create or replace procedure get_dir_list( p_directory in varchar2 )
as language java
name 'DirList.getList( java.lang.String )';
exec get_dir_list( 'c:\temp' );
select count(*) from dir_list;

Similar Messages

  • Why does OS X Finder recognize a folder as a file when it counts the number of files?

    When I select a folder in Finder and click cmd+i(or cmd+option+i), it shows the number of files in the folder. However, that number is weird for me, because they count a folder itself as a file. For example, when I have a single file in my Download folder and I clicked cmd+i on Download folder, then the number of files in a inspection window is 2, not 1. It is because that number includes not only the file inside the folder, but also the folder itself. (Check the below image)
    This is not a big problem if there is no hierarchical structure in my folder. But, if I have thousands of files and folders inside, it is really hard to figure out how many files(not folders) are inside. I cannot understand why Mac OS X counts a folder as a file. In fact, a folder is not an actual file, just a container.
    So, is there any philosophy to do like this? Or is there any way to count only the number of actual files?

    Sorry byron1st
    there is no way to count only files in a folder.
    Finder will count everything inside, folders and files.
    Information about a folder will count the same.
    If there are no subsubfolders in one folder, maybe a little trick can help:
    Select list view for the open folder, close all subfolders.
    Type command+# to see the footer of the window, that counts (hopefully) only the closed subfolders (content) in the open folder.
    Remember the amount.
    Hold option and click on one triangle in front of one subfolder. All subfolders will be opened!
    The difference between amount a and amount b is the number of files (and subsubfolders, if unfortunately inside…).

  • Where to find the number of files in a folder (in Finder)?

    I just upgraded from Snow Leopard.
    In the past I could look at the bottom of the finder window and see how many files where in a particular folder.  And how much megawattage they respresented in total.
    Is there some kind of preference I can set in Mountain Lion to be able to see the 'number' of files in a given folder?
    All ears,
    Ben

    Thank you Kurt,
    You're an ace.
    Much appreciated.
    Ben

  • How to count the  number of files read through  sender file adapter

    Hi  ,
    I have a scenario where I am reading  files from a third party system and trying to send those files to R/3 system .The frequency is 1 file per day .But there can be situation where  the source system can put  2 to 3 files in source folder and so XI sender adapter will pick up all the 3 files at time . And I want to send only 1 file at a time to r/3 .
    Do you know any way to handle this requirement ?
    Thanks ,
    Suvarna

    Hi,
    Like Bhavesh pointed out, you could EOIO as the Quality of Servie in the sender file adapter.
    But I guess this would solve your issue only to a certain extent.
    Marking this QOS in the sender file adapter would only mean sequential processing of the files. That is, the second file will be sent only when the first file is successfully received by the end system.
    It would not ensure that the files are sent only after 15 mins of the first file is sent.
    If the 15 mins time period is important, then this needs to be achieved using a BPM which ensures that the messages are sent to the target only every 15 mins.
    In case, the frequency of the incoming files is not known (in which case, the having a BPM would be a bad idea) you could use a ztable, which stores the filename and time the file was sent to the R/3.
    You could query this table each time, before sending the file data to the R/3
    Regards,
    Smitha.
    Message was edited by:
            Smitha Rao

  • Newbie: How to manage the number of files in a folder

    I have a backup application that runs each day and creates a file in a folder.
    I have an iCal scipt which automates this backup to run at a specific time but I would like to modify it so that it deletes the oldest file in the folder. I cannot figure out the best way to do this. Does anyone have any suggestions?

    This rather long script finds the oldest file in the complete nested range of a chosen outer folder and deletes it.
    property filePathList : {}
    property fileDateList : {}
    getEveryFileName((choose folder) as alias)
    Sort_items(fileDateList, filePathList)
    set oldest to item 1 of filePathList
    tell application "Finder" to delete oldest
    to getEveryFileName(theFolder)
    tell application "Finder"
    my getNamesDates(get files of theFolder)
    set FolderList to folders of theFolder
    repeat with everyFolder in FolderList
    my getEveryFileName(everyFolder)
    end repeat
    end tell
    end getEveryFileName
    to getNamesDates(FileList)
    repeat with everyFile in FileList
    try
    tell application "Finder"
    set end of fileDateList to modification date of everyFile
    set end of filePathList to everyFile as alias
    end tell
    on error anError
    display dialog anError
    end try
    end repeat
    end getNamesDates
    to Sort_items(sortList, SecondList)
    -- sorts by the first list (dates), while keeping the second list in the same order.
    tell (count sortList) to repeat with i from (it - 1) to 1 by -1
    set s to sortList's item i
    set r to SecondList's item i
    repeat with i from (i + 1) to it
    tell sortList's item i to if s > it then
    set sortList's item (i - 1) to it
    set SecondList's item (i - 1) to SecondList's item i
    else
    set sortList's item (i - 1) to s
    set SecondList's item (i - 1) to r
    exit repeat
    end if
    end repeat
    if it is i and s > sortList's end then
    set sortList's item it to s
    set SecondList's item it to r
    end if
    end repeat
    end Sort_items
    dual-core G5/2.3   Mac OS X (10.4.6)   dual screens

  • Displaying the number of files in a folder with Mountain Lion?

    I recently purchased a new iMac with Mountain Lion and I pretty much hate it. I have been a fan of just about EVERY update, so I am not resistant to change. I just think this is an inferior product. It is slow, clunky, and the update alerts remind me of everything that I hated about PCs. Meh.
    Anyway, one of the main problems I have with it is that in previous versions, when I opened a folder, there was a little bit of information at the bottom of the folder that told me how many files were in that folder. As a photographer, I use this information ALL THE TIME. I realize I can click on the folder and "get info" to see how many files are in it...but this is extremely inefficient (especially considering how slow the brand new system is -- in spite of the 3.4 Hz processor and 16GB of RAM).
    I can't seem to find anything in the preferences that allows me to change this. If there is a way, I would greatly appreciate it if someone would tell me how! Thank you!

    Active Memory: 1.88 GB
    Free Memory: 91.6 MB
    Wired Memory: 1.33 GB
    Used Memory: 15.90 GB
    Inactive Memory: 12.69 GB
    Total VM: 232.58 GB
    Number of processes: 92
    PID    Process Name              User       CPU      Real Mem        Virtual Mem   
    0      kernel_task               root       1.6      893.4 MB        10.17 GB        
    1      launchd                   root       0.0      2.3 MB          2.39 GB         
    11     UserEventAgent            root       0.0      4.6 MB          2.41 GB         
    12     kextd                     root       0.0      6.7 MB          2.39 GB         
    14     notifyd                   root       0.0      1.8 MB          2.40 GB         
    15     securityd                 root       0.0      10.2 MB         2.41 GB         
    16     diskarbitrationd          root       0.0      2.3 MB          2.39 GB         
    17     powerd                    root       0.0      2.4 MB          2.41 GB         
    18     configd                   root       0.0      4.9 MB          2.39 GB         
    19     syslogd                   root       0.0      1.5 MB          2.40 GB         
    20     cfprefsd                  root       0.0      1.8 MB          2.39 GB         
    21     distnoted                 root       0.0      2.3 MB          2.41 GB         
    22     opendirectoryd            root       0.0      11.8 MB         2.43 GB         
    30     warmd                     nobody     0.0      6.1 MB          2.39 GB         
    31     usbmuxd                   _usbmuxd   0.0      2.5 MB          2.40 GB         
    34     stackshot                 root       0.0      1.4 MB          2.39 GB         
    37     revisiond                 root       0.0      3.0 MB          2.41 GB         
    38     ptmd                      root       0.0      1.7 MB          2.38 GB         
    42     mds                       root       0.0      127.6 MB        2.93 GB         
    43     mDNSResponder             _mdnsrespo 0.0      3.9 MB          2.40 GB         
    46     loginwindow               karibedfor 0.0      22.0 MB         2.49 GB         
    47     locationd                 _locationd 0.0      7.9 MB          2.41 GB         
    48     KernelEventAgent          root       0.0      1.1 MB          2.37 GB         
    50     hidd                      root       0.6      3.2 MB          2.39 GB         
    51     fseventsd                 root       0.0      15.5 MB         2.42 GB         
    53     dynamic_pager             root       0.0      808 KB          2.32 GB         
    55     dpd                       root       0.0      1.9 MB          2.38 GB         
    56     appleeventsd              _eppc      0.0      3.2 MB          2.41 GB         
    59     blued                     root       0.0      4.6 MB          2.41 GB         
    61     autofsd                   root       0.0      2.1 MB          2.39 GB         
    62     apsd                      root       0.0      9.6 MB          2.41 GB         
    63     coreservicesd             root       0.0      24.8 MB         2.43 GB         
    66     WindowServer              _windowser 2.7      52.1 MB         2.97 GB         
    74     netbiosd                  _netbios   0.0      3.3 MB          2.40 GB         
    75     CVMServer                 root       0.0      1.9 MB          2.41 GB         
    91     networkd                  _networkd  0.0      1.4 MB          2.39 GB         
    100    aosnotifyd                root       0.0      8.5 MB          2.41 GB         
    113    logind                    root       0.0      2.0 MB          2.39 GB         
    114    coreaudiod                _coreaudio 2.2      9.3 MB          2.40 GB         
    120    launchd                   karibedfor 0.0      1.6 MB          2.39 GB         
    123    UserEventAgent            karibedfor 0.0      10.1 MB         2.41 GB         
    124    distnoted                 karibedfor 0.0      3.6 MB          2.41 GB         
    126    cfprefsd                  karibedfor 0.0      2.3 MB          2.39 GB         
    132    pboard                    karibedfor 0.0      996 KB          2.32 GB         
    137    usernoted                 karibedfor 0.0      4.4 MB          2.41 GB         
    141    talagent                  karibedfor 0.0      7.9 MB          2.43 GB         
    142    Dock                      karibedfor 0.0      31.0 MB         2.47 GB         
    143    SystemUIServer            karibedfor 0.0      23.3 MB         2.50 GB         
    144    Finder                    karibedfor 0.0      127.3 MB        2.66 GB         
    154    filecoordinationd         root       0.0      12.5 MB         2.39 GB         
    159    Notification Center       karibedfor 0.0      15.3 MB         2.46 GB         
    162    imagent                   karibedfor 0.0      6.6 MB          2.41 GB         
    169    AirPort Base Station Agen karibedfor 0.0      2.0 MB          2.38 GB         
    172    NetworkBrowserAgent       karibedfor 0.0      7.7 MB          2.41 GB         
    178    fontd                     karibedfor 0.0      5.8 MB          2.44 GB         
    181    Photo Stream              karibedfor 0.0      17.0 MB         2.44 GB         
    186    com.apple.dock.extra      karibedfor 0.0      18.1 MB         2.44 GB         
    187    lsboxd                    karibedfor 0.0      4.3 MB          2.41 GB         
    189    launchd                   _spotlight 0.0      1.0 MB          2.39 GB         
    192    distnoted                 _spotlight 0.0      1.9 MB          2.41 GB         
    216    AppleSpell.service        karibedfor 0.0      17.0 MB         2.44 GB         
    243    ntpd                      root       0.0      1.3 MB          2.32 GB         
    525    syspolicyd                root       0.0      7.5 MB          2.39 GB         
    569    Photo Mechanic            karibedfor 0.5      535.1 MB        1.33 GB         
    1047   storeagent                karibedfor 0.0      12.2 MB         2.42 GB         
    1061   maspushagent              karibedfor 0.0      5.5 MB          2.40 GB         
    2094   SleepServicesD            root       0.0      1.6 MB          2.34 GB         
    2118   cfprefsd                  _spotlight 0.0      1.4 MB          2.39 GB         
    2139   taskgated                 root       0.0      3.8 MB          2.40 GB         
    2156   cookied                   karibedfor 0.0      1.6 MB          2.39 GB         
    2176   Safari                    karibedfor 0.0      63.7 MB         3.57 GB         
    2181   xpcd                      karibedfor 0.0      6.6 MB          2.41 GB         
    2185   com.apple.iCloudHelper    karibedfor 0.0      6.2 MB          2.41 GB         
    2283   pbs                       karibedfor 0.0      6.9 MB          2.40 GB         
    2333   ocspd                     root       0.0      2.8 MB          2.37 GB         
    2347   accountsd                 karibedfor 0.0      5.2 MB          2.37 GB         
    2355   xpcd                      _spotlight 0.0      4.8 MB          2.36 GB         
    2370   mdworker                  karibedfor 0.0      10.2 MB         2.38 GB         
    2373   CalendarAgent             karibedfor 0.0      14.8 MB         2.41 GB         
    2374   tccd                      karibedfor 0.0      2.0 MB          2.36 GB         
    2376   Safari Web Content        karibedfor 0.3      207.2 MB        3.76 GB         
    2383   syncdefaultsd             karibedfor 0.0      12.4 MB         2.41 GB         
    2386   mdworker                  karibedfor 0.0      8.3 MB          2.37 GB         
    2387   Flash Player (Safari Inte karibedfor 0.9      48.4 MB         3.56 GB         
    2388   helpd                     karibedfor 0.0      2.2 MB          2.37 GB         
    2389   Activity Monitor          karibedfor 4.1      23.3 MB         2.49 GB         
    2391   activitymonitord          root       1.0      1.4 MB          2.33 GB         
    2392   CVMCompiler               karibedfor 0.0      20.3 MB         2.38 GB         
    2393   mdworker                  _spotlight 0.0      5.7 MB          2.36 GB         
    2394   mdworker                  _spotlight 0.0      10.3 MB         2.40 GB         
    2395   mdworker                  karibedfor 0.0      9.4 MB          2.40 GB         
    2396   sandboxd                  root       0.0      6.7 MB          2.41 GB         

  • [Win VC++ 6.0 ]How to get the number of files count in a folder using VC++ 6.0?

    Hi all,
    Can any one tell how to get the number of files(.EPS) count inside a folder when the folder path is specified in VC++ 6.0?
    Thanks in Advance.
    Regards
    myriaz

    I'm a little confused by the question, but it sounds like you're asking how to count the number of files with a particular extension in a given directory? That's not really an AI SDK question, but it's a fairly easy one to find if you google it. If you're trying to use Illustrator to do it, AI doesn't have a general purpose file API. It has a few functions to do some things that Illustrator needs, but I don't think enumerating directories is one of them.

  • Count the number of comments in a PDF file automatically?

    Hello O Experts,
    My documentation team members use Acrobat and Reader 8, and frequently need to count the number of comments in a PDF file. Is it possible to count the number of comments automatically? We can't find this functionality anywhere, and have to resort to manual counting. Since our PDFs can contain thousands of comments, this is very time-consuming. I've tried searching the Web and these forums, but the words "count" and "comments" are too frequent in other contexts to find anything useful...
    Thanks and best regards,
    --M.T.

    Hi again sypark,
    That is a great idea, and it works!
    I would actually search on a more unique phrase - for instance, "Subject:" - that definitively occurs a single time per comment. The reason is:
    There are many types of comments, not just sticky notes... you have highlights, text deletions, text insertions, replacement text, attachments, callouts, and so on. But each of them has a "Subject:" in the summary.
    It's best to avoid searching for the comment names because they differ by language (an important issue when you work with colleagues in multiple countries). For example, the name of the "Highlight" comment type in French is "Texte surligné" - so you'd have to search for the latter term to get an accurate count.
    In any case, your method is flexible and allows for easy customization of comment counts. Many thanks for your effective help!
    Cheers,
    --Michael

  • Count the number of lines in a txt file

    I need to count the number of lines in a txt file, but I can't do it using readLine(). This is because the txt file is double spaced. readLine() returns null even if it is not the end of the file. thanks for the help

    I need to count the number of lines in a txt file,
    but I can't do it using readLine(). Then just compare each single byte or char to the newline (code 10).
    This is because the txt file is double spaced. readLine() returns
    null even if it is not the end of the file.Errm what? What do you mean by "double spaced"? Method readLine() should only return null if there's nothing more to read.

  • Count the number of lines in  each file in a directory

    Hello,
    I would like to count the number of lines for each file in my directory and subdirectories.
    I wonder how can I count the lines of the specified files?
    Here is the program which is listed the files in the specified directory:
                        String path = "C:/User/Studies/Pracices/src/Pract1";
           String files;
           File folder = new File(path);
           File[] listOfFiles = folder.listFiles();
           for (int i = 0; i < listOfFiles.length; i++)
            if (listOfFiles.isFile())
         files = listOfFiles[i].getName();
         System.out.println(files);

    Ok so one more question.
    Actually my path is pointing to one Directory and like here I can just read from one file that the name of the file should be specified in the path is it possible to help me in that part?
    File f = new File("C:/User/Studies/Practices/src/Pract1/");
    FileReader fr = new FileReader(f);
          BufferedReader br = new BufferedReader(fr);
          String str = br.readLine();
              LineNumberReader ln = new LineNumberReader(br);
              int count = 0;
              while (ln.readLine()!=null)
                  count++;
              System.out.println("no. of lines in the file = " + count);

  • Count the number of occurences of a pattern in some files

    Hi,
    I am trying to extract some patterns in files using regex. I can easily extract the patterns using my program. I also wanted to count the number of occurences of the pattern in the files. For that I have written this code:
    int count=0;
              while (m.find())
                 System.out.println("Found Patterns: "+m.group());
                 count++;
           System.out.println(count);  //giving error saying identifier expectedUnfortunately I am getting an error saying identifier expected at the count line. What to do?
    Thanks

    Cheapside-Poultry wrote:
    Move the } down one line so the count is in scope.No, it looks like he just forgot the opening { with the while.                                                                                                                                                                                                                                                                                                                                       

  • Fastest way to count the number of occurences of string in file

    I have an application that will process a number of records in a plain text file, and the processing takes a long time. Therefore, I'd like to first calculate the number of records in the file so that I can display a progress dialog to the user (e.g. " 1234 out of 5678 records processed"). The records are separated by the string "//" followed by a newline, so all I need to do to get the number of records is to count the number of times that '//' occurs in the file. What's the quickest way to do this? On a test file of ~1.5 Gb with ~500 000 records, grep manages under 5 seconds, whereas a naive Java approach:
    BufferedReader bout = new BufferedReader (new FileReader (sourcefile));
                   String ffline = null;
                   int lcnt = 0;
                   int searchCount = 0;
                   while ((ffline = bout.readLine()) != null) {
                        lcnt++;
                        for(int searchIndex=0;searchIndex<ffline.length();) {
                             int index=ffline.indexOf(searchFor,searchIndex);
                             if(index!=-1) {
                                  //System.out.println("Line number " + lcnt);
                                  searchCount++;
                                  searchIndex+=index+searchLength;
                             } else {
                                  break;
                   }takes about 10 times as long:
    martin@martin-laptop:~$ time grep -c '//' Desktop/moresequences.gb
    544064
    real     0m4.449s
    user     0m3.880s
    sys     0m0.544s
    martin@martin-laptop:~$ time java WordCounter Desktop/moresequences.gb
    SearchCount = 544064
    real     0m42.719s
    user     0m40.843s
    sys     0m1.232sI suspect that dealing with the file as a whole, rather than line-by-line, might be quicker, based on previous experience with Perl.

    Reading lines is very slow. If your file has single byte character encoding then use something like the KMP algorithm on an BufferedInputStream to find the byte sequence of "//\n".getBytes(). If the file has a multi-byte encoding then use the KMP algorithm on a BufferedReader to find the chars "//\n".getCharacters() .
    The basis for this can be found in reply #12 of http://forum.java.sun.com/thread.jspa?threadID=769325&messageID=4386201 .
    Edited by: sabre150 on May 2, 2008 2:10 PM

  • How to count the number or rows in file

    Hi Experts,
    I am file as source and Oracle as target. My file containing the some data which is going to load to the target.
    My requirement is that I want to count the number of rows which my file contains. Please help me how to count the total number of rows in file.
    Thx,
    Sahadeva.

    Hi,
    You won't give a name DEST_USER_NAME:ODI will get these information.
    it is important  Command on source and Command on Source side .
    -Pls write jython code on Command on Source side
    -And Command On Target side Choose technology as Oracle and set logical schema to HR_logical
    Sorry my mistake.İt is related jython syntax.Here is code:
    import java.lang as lang
    import java.sql as sql
    import java.lang.String
    import os
    lang.Class.forName("<%=snpRef.getInfo("DEST_JAVA_DRIVER")%>")
    cons=sql.DriverManager.getConnection("<%=snpRef.getInfo("DEST_JAVA_URL")%>", "<%=snpRef.getInfo("DEST_USER_NAME")%>", "<%=snpRef.getInfo("DEST_PASS")%>")
    dblinks= cons.createStatement()
    file1=open('EMP.txt','r')
    count=0
    line=file1.readline()
    while line !='':
         count+=1
         line=file1.readline()
    file1.close()
    sqlQuery = "insert into HR.ETL_FILE_LOG (FILE_COUNT) values (count)"
    rqQuery= dblinks.execute(sqlDBLink)
    cons.close()
    Regards

  • Is there a way to count the number of times an array moves from positive to negative?

    I have an array of values, and I need to find the number of times that the array changes signs (from positive to negative, or vice versa). In other words from a graphical standpoint, how many times a certain line crosses the x-axis. Counting the number of times the array equals zero does not help however, because the array does not always equal exactly zero when it crosses the axis (ie, the points could move from .1 to -.1).
    Thanks for you help. Feel free to email me at [email protected] I only have lv 5.1.1 so if you attach any files, they cannot be version 6.0.

    Attached is a VI showing the # of Pos and Neg numbers in an array, with 0 considered as non-Pos. It is easily modifiable to other parameters - including using the X-axis value as your compare point versus only Zero.
    This is a modified VI from LV (Separate Array.vi)
    Compare this with your other responses to find the best fit.
    Doug
    Attachments:
    arraysizesposneg.vi ‏40 KB

  • How to Count the number of TAB chars value '0A' in a line?

    I have a requirement to count the number of TABs in a text file that I am processing (they must equal 75) to ensure that all the fields have been submitted on the file I am reading?
    How do I identify the TABs in a line?
    I have this so far:
             CONCATENATE gv_unix_file gv_lstfiles-name INTO gv_unix_file.
              OPEN DATASET gv_unix_file for INPUT IN TEXT MODE ENCODING NON-UNICODE.
              IF sy-subrc <> 0 .
                message e000(zz) with 'Cannot access in_uk files'.
              ENDIF.
              CONCATENATE gv_unix_file_arc gv_lstfiles-name INTO gv_unix_file_arc.
              OPEN DATASET gv_unix_file_arc FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE.
              IF sy-subrc <> 0 .
                message e000(zz) with 'Cannot access in_uk files'.
              ENDIF.
              DO.
                READ DATASET gv_unix_file into lv_str.
                IF sy-subrc <> 0.
                  exit. "exit do loop, file is done.
                else.
                  TRANSFER lv_str to gv_unix_file_arc.
                ENDIF.
              ENDDO.

    Here is a sample code:
    DATA: lv_string TYPE string,
          lv_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
          lv_i TYPE i.
    DATA: result_tab TYPE match_result_tab.
    DO 3 TIMES.
      CONCATENATE 'A' lv_string INTO lv_string SEPARATED BY lv_tab.
    ENDDO.
    " this is how you need to find how many tabs are in your transfer work area...
    FIND ALL OCCURRENCES OF lv_tab IN lv_string RESULTS result_tab.
    DESCRIBE TABLE result_tab LINES lv_i.
    WRITE:'No. of tabs found:', lv_i.

Maybe you are looking for