Finding the number of files in a directory

hi,
im trying to return the count of all the files that are available in a specific directory. does anyone know how or what method would spport this?
Im new to Java and swing please help!
Thanks

Hi,
all you need is provided by the File class. With this class you can work with "physical" files.
Try this:
String path = "your directory";
File file = new File(path);
String[] fileArray;
try{
fileArray = file.list();
//you need fileArray.length
System.out.println("Number of files found in "+path+ fileArray.length);
}catch(SecurityException se){
//handle exception
}

Similar Messages

  • How to find the number of files in an oracle directory through a storedproc

    hi
    i have an oracle directory or a directory in an ftp server
    is there any way.......through which..
    i can know the number of files in the directory ...?
    and whats the metadatacolumn that will indicate the name of the file?
    and is it possible to loop through each of the entries within oracle
    regards
    raj

    ops$tkyte@8i> GRANT JAVAUSERPRIV to ops$tkyte
      2  /
    Grant succeeded.
    That grant must be given to the owner of the procedure..  Allows them to read
    directories.
    ops$tkyte@8i> create global temporary table DIR_LIST
      2  ( filename varchar2(255) )
      3  on commit delete rows
      4  /
    Table created.
    ops$tkyte@8i> create or replace
      2     and compile java source named "DirList"
      3  as
      4  import java.io.*;
      5  import java.sql.*;
      6 
      7  public class DirList
      8  {
      9  public static void getList(String directory)
    10                     throws SQLException
    11  {
    12      File path = new File( directory );
    13      String[] list = path.list();
    14      String element;
    15 
    16      for(int i = 0; i < list.length; i++)
    17      {
    18          element = list;
    19 #sql { INSERT INTO DIR_LIST (FILENAME)
    20 VALUES (:element) };
    21 }
    22 }
    23
    24 }
    25 /
    Java created.
    ops$tkyte@8i>
    ops$tkyte@8i> create or replace
    2 procedure get_dir_list( p_directory in varchar2 )
    3 as language java
    4 name 'DirList.getList( java.lang.String )';
    5 /
    Procedure created.
    ops$tkyte@8i>
    ops$tkyte@8i> exec get_dir_list( '/tmp' );
    PL/SQL procedure successfully completed.
    ops$tkyte@8i> select * from dir_list where rownum < 5;
    FILENAME
    data.dat
    .rpc_door
    .pcmcia
    ps_data
    http://asktom.oracle.com/pls/asktom/f?p=100:11:4403621974400865::::P11_QUESTION_ID:439619916584
    Edited by: Salim Chelabi on 2009-04-21 10:37

  • 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 do I find the number of file descriptors in use by the system?

    Hey folks,
    I am trying to figure out how many file descriptors my Leopard system has in use. On FreeBSD, this is exposed via sysctl at the OID kern.open_files (or something close to that, can't recall exactly what the name is). I do see that OS X has kern.maxfiles, which gives the maximum number of file descriptors the system can have open, but I don't see a sysctl that tells me how many of the 12288 descriptors the kernel thinks are in use.
    There's lsof, but is that really the only way? And, I'm not even sure if I can just equate the number of lines from lsof to the number of in use descriptors. I don't think it's that easy (perhaps it is and I'm just over complicating things).
    So, anyone know where this information is?
    Thanks for your time.

    glsmith wrote:
    There's lsof, but is that really the only way? And, I'm not even sure if I can just equate the number of lines from lsof to the number of in use descriptors.
    Can't think of anything other than lsof right now. However:
    Only root can list all open files, all other users see only their own
    There is significant duplication, and
    All types of file descriptor are listed, which you may not want, so you need to consider filtering.
    As an example, the following will count all regular files opened by all users:
    sudo lsof | awk '/REG/ { print $NF }' | sort -u | wc -lIf you run it without the sudo, you get just your own open files.

  • Checking Number of Files in a Directory

    Hi
    How can I read the filenames in a directory and determine the number of files in this directory.I need to put all the filenames in a drop down list box on a JSP.
    Please Advise

    FilenameFilter filter = new FilenameFilter() {
      public boolean accept(File dir, String name) {
        File file = new File(dir, name);
        return file.isFile(); // true if file, false if directory
    File dir = new File("c:\\temp"); // the directory we want to list the files from
    File[] files = dir.listFiles(filter);
    // or String[] files = dir.list(filter); I haven't checked the code, so there might be some typos..

  • Finder issues and Get Info refusing to show the number of files on items on the main hard drive.

    I am having finder issues. Mostly on the main hard drive. It takes ages to find things and I get the spinning wheel every time I open a folder.
    So I moved all of my files to a external drive.  When I had finished transfering I hit get info on the files on the external drive and on the same folder on the main drive.  To ensure that it has copied over all the files.  Because it was acting up and not copying all the files.
    Get Info refuses to show the number of files within the folders on the main hard drive. It hasppily tells me everything on any of the external drives.
    I have reset, the imac.  I have re indexed 3 times.  I have deleted the finder plist files.  I have reset finder using terminal commands. I have moved nearly everything off the main hard drive. But nothing is working.
    Can anyone offer any suggestions as to what could be causing my finder and get info issues.
    Any help wpuld be appreciated.
    Running Mountain Lion on a late 2009 Imac

    Some of your user files (not system files) have incorrect permissions or are locked. This procedure will unlock those files and reset their ownership, permissions, and access controls to the default. If you've intentionally set special values for those attributes, they will be reverted. In that case, either stop here, or be prepared to recreate the settings if necessary. Do so only after verifying that those settings didn't cause the problem. If none of this is meaningful to you, you don't need to worry about it, but you do need to follow the instructions below.
    Back up all data.
    Step 1
    If you have more than one user, and the one in question is not an administrator, then go to Step 2.
    Enter the following command in the Terminal window in the same way as before (triple-click, copy, and paste):
    sudo find ~ $TMPDIR.. -exec chflags nouchg,nouappnd,noschg,nosappnd {} + -exec chown $UID {} + -exec chmod +rw {} + -exec chmod -N {} + -type d -exec chmod +x {} + 2>&-
    This time you'll be prompted for your login password, which won't be displayed when you type it. Type carefully and then press return. You may get a one-time warning to be careful. If you don’t have a login password, you’ll need to set one before you can run the command. If you see a message that your username "is not in the sudoers file," then you're not logged in as an administrator.
    The command may take several minutes to run, depending on how many files you have. Wait for a new line ending in a dollar sign ($) to appear, then quit Terminal.
    Step 2 (optional)
    Take this step only if you have trouble with Step 1, if you prefer not to take it, or if it doesn't solve the problem.
    Start up in Recovery mode. When the OS X Utilities screen appears, select
              Utilities ▹ Terminal
    from the menu bar. A Terminal window will open. In that window, type this:
    res
    Press the tab key. The partial command you typed will automatically be completed to this:
    resetpassword
    Press return. A Reset Password window will open. You’re not going to reset a password.
    Select your startup volume ("Macintosh HD," unless you gave it a different name) if not already selected.
    Select your username from the menu labeled Select the user account if not already selected.
    Under Reset Home Directory Permissions and ACLs, click the Reset button
    Select
               ▹ Restart
    from the menu bar.

  • How to find the number of data items in a file written with ArryToFile function?

    I have written an array of number in 2 column groups to a file using the LabWindows/CVI function ArrayToFile...Now if I want to read the file with FileToArray Function then how do I know the number of items in the file. during the write time I know how many array items to write. but suppose I want the file to read at some later time then How to find the number of items in the file,So that I can read the exact number and present it. Thanks to all
    If you are young work to Learn, not to earn.
    Solved!
    Go to Solution.

    What about:
    OpenFile ( your file );
    cnt = 0;
    while ((br = ReadLine ( ... )) != -2) {
    if (br == -1) {
    // I/O error: handle it!
    break;
    cnt++;
    CloseFile ( ... );
    There are some ways to improve performance of this code, but if you are not reading thousands of lines it's quite fast.
    After this part you can dimension the array to pass to FileToArray... unless you want to read it yourself since you already have it open!
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • How do you find the number of lines in a file?

    I need to count how many lines there are in a file, I am using a BufferedReader to read in the data, but how can I find the number of lines?
    Thanks

    That depends. How do you define a line? Is it a specific number of
    characters, a String that's terminated by a newline character or some
    combination thereof?

  • VB Script to find the last modified file and time in a directory

    Hi,
    I am new to VB script i need a script to find the latest modifed file and last modifed time in a directory(Contains  folders and sub folders inside it). it has to go through all the folders and get the latest file and last modifed time.

    Thanks it worked for me Get-ChildItem C:\Users\sujith.reddy.komma\Desktop\Suj1\* -recurse |?{-not $_.PsIsContainer} |Sort LastWriteTime -desc | select -first 1 now in my script i have hard coded the directory i need to run this script in different
    servers from one location i will put all the different paths in one text file and ineed to pass them to this script can you help me with this?
    Essentially you are incrementally asking us to write each line for you.  I recommend freeing yourself of this misery and leraning PowerShell.  THe answers to all of your questions are learned in the first few hours of study.
    Start here:
    http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx
    ¯\_(ツ)_/¯

  • 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…).

  • Can we find the number of rows in table from the dump file

    Hi All,
    Can we find the number of rows in table from the dump file with out importing the table in to the database?
    Please let me know ,if any option is there.
    Thanks,
    Kumar.

    <s>Try to import with option SHOW=Y, that should skip the number of rows which are into a table from a dump file.</s><br>
    <br>
    Nicolas.<br>
    Oops, sorry, that doesn't show the number of lines...<br>
    Message was edited by: <br>
    N. Gasparotto

  • Finding the number of Non-Blank Line in a File

    Does anyone know the command or how to find the number of non-blank lines in a text file? I have the program already reading characters, words, and total lines.
              BufferedReader FileIn = new BufferedReader( new FileReader( selectedFile ) );
                   Scanner scanWords = new Scanner (selectedFile);
                             String thisToken = "";
                             int numWords = 0;
                             while (scanWords.hasNext())
                             thisToken = scanWords.next();
                             numWords++;
         System.out.println("Total number of words: " + numWords);
         Scanner scanLines = new Scanner (selectedFile).useDelimiter("\n");
                             String thisToken2 = "";
                             int numLines = 0;
                             while (scanLines.hasNext())
                             thisToken2 = scanLines.next();
                             numLines++;
         System.out.println("Total number of lines: " + numLines);
         Scanner scanChars = new Scanner (selectedFile).useDelimiter("");
                             String thisToken3 = "";
                             int numChars = 0;
                             while (scanChars.hasNext())
                             thisToken2 = scanChars.next();
                             numChars++;
         System.out.println("Total number of characters: " + numChars);
                   FileIn.close();
              }

    Use BufferedReader#readLine() instead. Read the file once and process each line once.

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

  • How can i find total no of files in a directory ..using fileconnection

    how can i find total no of files in a directory.
    currently iam using
    Enumeration enum = fileconn.list(); and by iterating iam getting count.
    but the application is getting stuckup when the number of files in the directory is large.
    Is there any alternative. please help.
    thanks in advance.

    HI,
    this is a simple example with a cursor over user_tables view:
    set serveroutput on
    DECLARE
       CURSOR c_test IS
          SELECT table_name FROM user_tables;
       type t_reg is table of varchar2(30);
       l_reg t_reg;
    BEGIN
       OPEN c_test;
       fetch c_test bulk collect into l_reg;
       dbms_output.put_line(c_test%ROWCOUNT);
    END;
    /Output:
    SQL>
    SQL> set serveroutput on
    SQL> DECLARE
      2     CURSOR c_test IS
      3        SELECT table_name FROM user_tables;
      4     type t_reg is table of varchar2(30);
      5     l_reg t_reg;
      6  BEGIN
      7     OPEN c_test;
      8 
      9     fetch c_test bulk collect into l_reg;
    10 
    11     dbms_output.put_line(c_test%ROWCOUNT);
    12  END;
    13  /
    42
    PL/SQL procedure successfully completed
    SQL> Regards,
    Edited by: Walter Fernández on Nov 29, 2008 8:59 AM - Adding output...

  • "Get Info" Reports an Incorrect Number of Files in a Directory

    I have a 17" MacBook Pro with OS X, 10.6.4. I've been relying upon Finder's "Get Info" to determine how many files a directory contains, and I never noticed any problems when using it. However, this afternoon I saw an anomaly with the actual number of files in a directory and what "Get Info" reported.
    I had previously created a new directory and moved 23 files to it. This morning I added three (3) more files to the directory, for a total of 26 files. This afternoon I added another five (5) files for a final total of 31 files in the directory. While Finder's "Get Info" showed that the directory had been updated this afternoon, it would not update the number of files it contains -- it still showed 26 files and the old total file size. I had to log out and log back in again for it to show me the correct file size and number of files.
    Is this normal behavior or was it a glitch in Finder? That is, can I rely upon Finder to tell me the correct number of files in a folder -- or not?
    Is there a way to force Finder to refresh itself? I looked around, but I did not see anything obvious, which is why I tried the logout/login method of refreshing it.
    Thanks,
    Bev in TX

    Welcome to Apple Discussions.
    This is a known issue in Finder. No fix I know of but a decent refresh here.
    -mj

Maybe you are looking for

  • Third Party VPN Solution - Private/Dynamic Addressing

    I am looking for a solution for the following: I need a to bring up sites in remote locations that don't have access to Cisco gear. I would like to be able to grab a PC or Linksys or equivalent and bring up a site to site VPN with a Cisco router. The

  • Bug safari 3 in Windows Home Server

    Hello, I tried to test Safari 3 Beta on Windows Home Server and I've found a bug on the beginning a window called 'Microsoft Visual C + + Runtime Library with a "runtime error"

  • Robot Test fails  with error message Invalid command line: process must be

    public class test     public static void main(String [] args) throws Exception         new java.awt.Robot(); }I'm using SLES Linux. Is there any problem in my machine ? How Robot tests generally works ? Thanks !

  • Check printing script debuggin problem

    Hi i am working on a check printing script. i need to adjust the layout of few things in this layout. in the debuggin mode i am getting the short dump stating vendor number = xxxxxxxxxxxx (invalid). can anyone tel me the windows for date,account paye

  • Hyperion Services Restart Doc

    Hello All, Can anyone pls let me know where i can find the document to stop and start all the hyperion services version 11.1.1.3 and 11.1.2.1? Thanks, Ashu Edited by: Ashu on 11-Jan-2013 07:10