How to get all files in one directory

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

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

Similar Messages

  • Multiple devices on same account - how to transfer ALL files in one place?

    Hi,
    I am using my Apple ID on 5 apple devices, incl. 2 laptops and Mac. Need to migrate all files to one computer for syncing with iPhone and cut out some devices, but...
    Question 1:  How I can move ALL my music files from old MB Pro (runs Mac OS X 10.5.8) with iTunes 10 to Mac (runs Mac OS X 10.9.2) with iTunes 11.1.5?
    Note, this includes songs purchased outside of iTunes and burnt from CDs. Is it possible to somehow easily identify the songs that are missing on Mac and copy just them from the old computer, but without manually comparing? For now for whatever reason Mac only has 401 songs vs my old MB Pro has 1670+ songs. So, please suggest how to make the import on the missing songs to Mac as efficient as possible.
    Question 2: How do I deauthorize the device once I copy my old music to Mac? Currently only see the button "Deathorize All" in iTunes on Mac. What if I want to choose which computers I still want to be able to stay on the same Apple ID in iTunes?
    Thanks a lot!!

    Decide which Mac is your primary. On the Mac that is not the primary - create a folder on the desktop - drag all the tunes from iTunes into that folder - copy that folder to an ext HD or a memory stick.
    Plug into the primary Mac and tell iTunes to import all the tunes from the folder.
    iTunes has good sort options so it won't take long to get rid of the duplicates using the Show Duplicates from the View dropdown menu.
    An alternative would be to check at http://dougscripts.com/itunes/ and see if there is a script that will take care of what you want.
    MJ

  • How to remove all files in a directory in java?

    I have tried method delete() of File ,
    but no effect!
    can anyone help me!
    thank you

    So, you have a directory and you want to delete all files in the directory. Here is some (untested) code:
    File dir = new File("C:\\tempdir");
    File[] files = dir.listFiles();
    for (int i = 0; i < files.length; ++i) {
      if (files.isFile()) {
    files[i].delete();
    Jesper

  • How to get all songs on one album artwork

    I have 1 album that is listed twice on the albums list. I have 2 songs on one and one song on the other. I cannot get them all on just one. I have checked all the info on the info tab and everything is the same. I have copied all the songs in one file on my desktop and deleted everything from itunes and my music folder and when I add it back to that artist it adds two. The only thing that is different is one song was downloaded on itunes and the other 2 were from a CD.
    selected all the songs and when to get info and retyped the name of the artist and the artist album and fixed it like blood sugar sex magik.

    how about the less painful click the first song then shift-click the last song?

  • How to get the file name from directory

    Hi,
    I have a directory called test inside i have only one .txt file. i dont know that file name.
    Is it possible get the file name using PL/SQl code. ???
    Using that .txt file i have to create a dynamic table.
    If i have use *.txt also not working
    Anyone suggest me its possible to do or not????
    Cheers,
    Shan

    Hi Saubhik ,
    Wheni execute the function i am getting the following error
    Warning: compiled but with compilation errors
    Errors for FUNCTION LISTDIR
    LINE/COL                                                                       
    ERROR                                                                          
    7/3                                                                            
    PLS-00201: identifier 'DBMS_BACKUP_RESTORE.SEARCHFILES' must be declared       
    7/3                                                                            
    PL/SQL: Statement ignored                                                      
    8/54                                                                           
    PL/SQL: ORA-00942: table or view does not exist                                
    8/20                                                                           
    PL/SQL: SQL Statement ignored                                                  
    10/11                                                                          
    PLS-00364: loop index variable 'EACH_FILE' use is invalid                      
    10/2                                                                           
    PL/SQL: Statement ignored      Cheers,
    Shan

  • How to get certificate from sun one directory server

    I have installed sun one directory server 5.2. Now in order to connect to the server through ldap protocol i need certificate on the client side.
    How to get the certificate from the sun one directory server...??
    ( Earlier i tried the same procedure with active directory .and i got the certificate successfully ...as well as ldap authentication..but don't know what to do with the sun one..???)
    Any tips on this issue will be helpful
    thank you

    You didn't make mention of setting up ssl on the server side, so search these boards for openssl. Some nice person uploaded an nice example of how do use openssl to do this.
    To get the ssl certs for the solaris-client ssl authentication ( tls:simple ) to work you will need to use netscape to connect to the ssl port to get the right format. There are comments in that same doc on how to do that.

  • How to get all JFrames in one window.

    I have a JFrame with menu system. When the user opens a file using the menus and filechoosers,another JFrame is called wherein the required output is displayed. If another file is chosen,the data of the previous file is not cleared from the runtime memory. What additional statement is needed to debug this program?
    Also on clicking the second menu and the menuitems therein,each JFrame instance is created with the required outputs. How to make all these JFrame instances in a single window? I tried the JDesktopPane but with no success.

    JFileChooser jfc = new JFileChooser();
    JMenuBar jmb = new JMenuBar();
    JMenu jm1 = new JMenu("File");
    JMenu jm2 = new JMenu("Plot");
    JMenuItem jmi1 = new JMenuItem("Open Alt+O",new ImageIcon("Open.gif"));
    JMenuItem jmi2 = new JMenuItem("Exit");
    JMenuItem jmi3 = new JMenuItem("Graph");
    public void actionPerformed(ActionEvent ae){
         if (ae.getSource()==jmi1){
              int result = jfc.showOpenDialog(null);
              File file = jfc.getSelectedFile();
              String ftr = file.toString();
              System.out.println("The file selected is "+ftr);
              ftr.trim();
              if (result == JFileChooser.APPROVE_OPTION){
                   try{
                        RandomAccessFile raf = new RandomAccessFile(ftr,"r");
                        long l = 0;
                        while (l < raf.length()){
                             String str = raf.readLine().toString();
                             l = raf.getFilePointer();
                   jm2.setEnabled(true);
                   frame("Frame");
                   raf.close();
              }catch (Exception e){
                   System.out.println("Exception caught is "+e.toString());
         }else if (result == JFileChooser.CANCEL_OPTION){
              jfc.cancelSelection();
         }else if (ae.getSource()== jmi2){
              System.exit(0);
         }else if (ae.getSource()== jmi3){
              graph("Graph");
    static void frame(String title){
         JFrame frame = new JFrame(title);
         frame.getContentPane().add(new GraphPanel(), BorderLayout.CENTER);
         frame.setDefaultCloseOperation(2);
         frame.pack();
         frame.setVisible(true);
    static void graph(String title){
         JFrame frame = new JFrame(title);
         frame.getContentPane().add(new Graph(), BorderLayout.CENTER);
         frame.setDefaultCloseOperation(2);
         frame.pack();
         frame.setVisible(true);
    Whre should I use frame.setVisible(false); and frame.dispose();

  • How to Move  a file from one Directory to another directory.

    Hi All
    i am having a Java standlone Application reqiurements are
    1---->Connection pool To be Created.
    2---->Using Thread to read Multiple Files Simulatneously.
    3----->After Reading Those file I have to Move it to another folder.
    Plz help me.If possible give me sample code .
    I am in deep trouble for this project.

    Use java.io.File.renameTo(...) (look it up in the API documentation).
    Renaming a file doesn't work if you're trying to move files from one disk to another disk. In that case, you have to copy the file and delete the original.

  • How to get all files from Archive server

    Hi Experts,
    My problem is:
    When i try to read from an archived file, the moment archive_open_for_read function module is executed, a popup box appears
    asking to choose the name of the archive file to be read.
    I have to pass only one Export Parameter i.e. Archive Object.
    How to avoid the popup screen from appearing. I want to read all the archived files by default, the values are to be retrived from the archived files and displayed.
    Thanks,
    Parthow.

    Hi,
    I probably didn't understand your question, as I think my answer is exactly what you expect.
    In an archive object, you may have 1 or more files. If you want to know the list of files in the object, you have to use ARCHIVOBJECT_GET_TABLE.
    Sandra

  • How do I Copy files from one directory to another?

    I know how to move files using the renameTo() method of File class, but is there a simple way to copy files, without the need of reading the input stream form one file and writing to a new one?

    Hi all,
    I ripped this off the jakarta-ant project's file copier (with a small tweak)..
    package com.museumcompany.util;
    import java.io.IOException;
    import java.io.File;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.lang.reflect.Method;
    import java.text.DecimalFormat;
    import java.util.Random;
    import java.util.Stack;
    import java.util.StringTokenizer;
    * This class also encapsulates methods which allow Files to be
    * refered to using abstract path names which are translated to native
    * system file paths at runtime as well as copying files or setting
    * there last modification time.
    * @author [email protected]
    * @author Conor MacNeill
    * @author Stefan Bodewig
    * @version $Revision: 1.8 $
    public class FileUtils {
    private static Random rand = new Random(System.currentTimeMillis());
    private static Object lockReflection = new Object();
    * Factory method.
    public static FileUtils newFileUtils() {
    return new FileUtils();
    * Empty constructor.
    protected FileUtils() {}
    * Convienence method to copy a file from a source to a destination.
    * Overwrite is prevented, and the last modified is kept.
    * @throws IOException
    public void copyFile(String sourceFile, String destFile) throws IOException {
    copyFile(new File(sourceFile), new File(destFile), false, true);
    * Method to copy a file from a source to a
    * destination specifying if
    * source files may overwrite newer destination files and the
    * last modified time of <code>destFile</code> file should be made equal
    * to the last modified time of <code>sourceFile</code>.
    * @throws IOException
    public void copyFile(File sourceFile, File destFile,
    boolean overwrite, boolean preserveLastModified)
    throws IOException {
    if (overwrite || !destFile.exists() ||
    destFile.lastModified() < sourceFile.lastModified()) {
    if (destFile.exists() && destFile.isFile()) {
    destFile.delete();
    // ensure that parent dir of dest file exists!
    // not using getParentFile method to stay 1.1 compat
    File parent = new File(destFile.getParent());
    if (!parent.exists()) {
    parent.mkdirs();
    FileInputStream in = new FileInputStream(sourceFile);
    FileOutputStream out = new FileOutputStream(destFile);
    byte[] buffer = new byte[8 * 1024];
    int count = 0;
    do {
    out.write(buffer, 0, count);
    count = in.read(buffer, 0, buffer.length);
    } while (count != -1);
    in.close();
    out.close();
    if (preserveLastModified) {
    destFile.setLastModified(sourceFile.lastModified());
    public File createTempFile(String prefix, String suffix, File parentDir) {
    File result = null;
    DecimalFormat fmt = new DecimalFormat("#####");
    synchronized (rand) {
    do {
    result = new File(parentDir,
    prefix + fmt.format(rand.nextInt())
    + suffix);
    } while (result.exists());
    return result;

  • How to delete all file in a directory

    Hi,
    Myself is Lokesh....can anyone tell me how can we delete all existing mail file which i kept in linux (PATH IS: /usr/share/mailfile/)...the mail file extension is *.MAIL. Please help me in sortout this problem...

    See listFiles (FileFilter) and delete ().

  • Log4j : how to get log file name and directory

    My log4j is working fine. Below is how I define the property file
    log4j.rootCategory=DEBUG, A1
    log4j.appender.A1=org.apache.log4j.RollingFileAppender
    log4j.appender.A1.layout=org.apache.log4j.PatternLayout
    log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
    log4j.appender.A1.File=temp/log.txtI want to know, from my java program, how to retrieve my log file "temp/log.txt" because I want to display at console and notify user where to find the log file.
    Thanks

    Or perhaps I did not understand your requirement. Which of the following is it?
    1. Given some Java class, you need to do something with its source code?
    2. Given some file whose path is specified by user input or runtime configuration or compile-time constant, you need to do something with that file?
    3. Neither of the above?
    If 1: Can't do it. Don't need to do it. Don't waste your time trying. Unless you're writing something like a debugger. If so, then if you have to ask this question, you do not have the skills necessary for the broader task.
    If 2: Google for java io tutorial. Study it, try some code, and come back with a more specific question if you're still confused.
    If 3: Explain clearly what you're trying to accomplish and why you think this approach is the right one.

  • How to get ALL validate-errors while insert xml-file into xml_schema_table

    How to get all validate-errors while using insert into xml_schema when having a xml-instance with more then one error inside ?
    Hi,
    I can validate a xml-file by using isSchemaValid() - function to get the validate-status 0 or 1 .
    To get a error-output about the reason I do validate
    the xml-file against xdb-schema, by insert it into schema_table.
    When more than one validate-errors inside the xml-file,
    the exception shows me the first error only.
    How to get all errors at one time ?
    regards
    Norbert
    ... for example like this matter:
    declare
         xmldoc CLOB;
         vStatus varchar
    begin     
    -- ... create xmldoc by using DBMS_XMLGEN ...
    -- validate by using insert ( I do not need insert ;-) )      
         begin
         -- there is the xml_schema in xdb with defaultTable XML_SCHEMA_DEFAULT_TABLE     
         insert into XML_SCHEMA_DEFAULT_TABLE values (xmltype(xmldoc) ) ;
         vStatus := 'XML-Instance is valid ' ;
         exception
         when others then
         -- it's only the first error while parsing the xml-file :     
              vStatus := 'Instance is NOT valid: '||sqlerrm ;
              dbms_output.put_line( vStatus );      
         end ;
    end ;

    If I am not mistaken, the you probably could google this one while using "Steven Feuerstein Validation" or such. I know I have seen a very decent validation / error handling from Steven about this.

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

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

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

  • Get all files from Directory

    Hi All,
    My requirment is to get releted files from Local Directory.
    For Example Path is "D/Data/"
    in this path there is files like
    abc123_de.txt
    abc123_en.txt
    xyz123_de.txt
    abc123_pt.txt
    xyz123_en.txt
    pqr123_en.txt
    bcg234_en.txt
    sjd467_en.txt
    Now i want to use only files which are strart from abc123 and use their data.
    From which FM i can do it or how can i do this?
    Thanks,
    Mahipalsinh

    Dear Mahipalsinh,
    I have got the same requirement some days back, i think there is no FM for your requirement. so what i did, i have get all the files using below FM and Concatenate the ABC.
    Please use the Below FM, because if the file name is above that 50 character that time always it gives the full file name. Please check, if u used the other one for getting the Files.
       CALL FUNCTION 'EPS2_GET_DIRECTORY_LISTING'
         EXPORTING
           iv_dir_name            = lv_dir_name
         TABLES
           dir_list               = lt_file_name
         EXCEPTIONS
           invalid_eps_subdir     = 1
           sapgparam_failed       = 2
           build_directory_failed = 3
           no_authorization       = 4
           read_directory_failed  = 5
           too_many_read_errors   = 6
           empty_directory_list   = 7
           OTHERS                 = 8.
       IF sy-subrc <> 0.
    * Implement suitable error handling here
       ENDIF.
    For reading Specific Files.
    CONCATENATE 'AP' lv_internal_date INTO lv_filename.
             LOOP AT  lt_file_name INTO ls_file_name.
               lv_index = sy-tabix.
               IF ls_file_name-name CS lv_filename.
              " PUT YOUR LOGIC
              endif.
         endloop.
    Thanks,
    Nishant

Maybe you are looking for