Getting the list of  files in a directory by their last modified date

Dear friends,
I want to get the list of files in a directory sorted by their last modified date.
By default the file.list() or listFiles() return files sorted by their name in ascending order.
Please give me your suggestions.
Thanks in advance,
James.

Thanks friend,
I myself got the answer
here is my code:
public File[] getSortedFileList(File dir){
File[] originalList = dir.listFiles();
int numberOfFiles = originalList.length;
File[] sortedList = new File[numberOfFiles];
long[] lastModified = new long[numberOfFiles];
for(int i = 0; i < numberOfFiles; i++){
lastModified[i] = originalList.lastModified();
Arrays.sort(lastModified);
for(int i = 0; i < numberOfFiles; i++){
for(int k = 0; k < numberOfFiles; k++){
if(originalList[k].lastModified() == lastModified[i])
sortedList[i] = originalList[k];
System.out.println("The sorted file list is:" + sortedList[i]);
return sortedList;

Similar Messages

  • How to get the list of files of floder

    hello,
    I am using Forms 6i , i want to get the list of file of the directory
    which function i have to use,
    thx.

    In this demo you will find an example
    http://www.oracle.com/technology/sample_code/products/forms/6idemos.html
    Regards

  • How to get the current executing file/itself absolute directory?

    hellooo,
              gentlemen/lady, how to get the current executing file/itself absolute directory?
              thanks
              

              Hello,
              you can get the real path information of the JSP through the servlet context:
              http://java.sun.com/products/servlet/2.2/javadoc/index.html
              javax.servlet
              Interface ServletContext
              Method getRealPath
              Christian Plenagl
              Developer Relations Engineer
              BEA Support
              [email protected] (alex mok) wrote:
              >hellooo,
              >
              >gentlemen/lady, how to get the current executing file/itself absolute
              >directory?
              >
              >thanks
              

  • Problem with getting a list of files in a directory

    I'm trying to get a list of files in a particular directory. The problem is I'm also getting a listing of all the sub-directories too. Here is my code:
    File directory = new File(dir);
    File[] filelist;
    filelist = directory.listFiles();
    for(int i=0;i<filelist.length;i++)
    System.out.println("FileName = " + filelist.getName());
    What am I doing wrong?
    Thanks
    Brad

    You are not doing anything wrong. You just have to test whether a given file is a subdirectory:
    File directory = new File(dir);
    File[] filelist;
    filelist = directory.listFiles();
    for(int n = 0; n < filelist.length; n++) {
      if (!filelist[n].isDirectory())
        System.out.println("FileName = " + filelist[n].getName());
    }S&oslash;ren Bak

  • How to get the list of file from application server

    Hi Expert.
    I want to get the file list from dicrectory in application server
    best regards.
    Alex

    Hi.
    Yes, You are right, i can get the file list by AL11.
    But i need get the list in ABAP program.
    So i need a function modul to get the list. If you has some sample code, it should be very nice.
    Best.
    Alex

  • How do I get a list of files in the DataDrvUser Dir programatically (no dialogs)

    I have version 8.1.1292 of Diadem. I wish to get a list of files in a directory without using a dialog.

    Hello Sweeten
    Attached are two snipits of code, hope this helps
    The following sub reads all the folders in a root folder. Note the use the FSO or file system object. The FSO has a number of properties and methods for working with files and folders, would definetly check it out.
    Sub ReadProjects()
    'This sub reads all the Folders in the root
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set Folder = fso.Getfolder(RootPath_)
    Set Folder = Folder.SubFolders
    i=1
    For Each SubFolder In Folder
    LstStates.Items.add SubFolder.name,i
    i=i+1
    Next
    End Sub
    This next code snipit reads all the files of a certain extention (i.e. LPD,DAT)
    Sub ReadProjectFiles()
    Dim fso,PathName,LvdNames,GraNames,path
    Dim x,y,z
    x=1:y=1:z
    =1:w=1
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set Folder = fso.Getfolder(ProjectPath_)
    Set Files = Folder.Files
    For Each file In files
    Select Case file.type
    Case "LPD File"
    LstGraph.items.add file.name , x
    x=x+1
    Case "DAT File"
    LstData.Items.add file.name , y
    y = y+1
    Case "LVD File"
    LstView.Items.add file.name , z
    z = z+1
    End Select
    Next
    Let me know if this is helpful
    Tom Ferraro
    DIAdem Product Manager
    512-683-6841

  • List of Files in a directory

    Is there a way that you can get a list of files in a directory that are spelt a certain way? Ex. If in a directory there are html files, txt files, et, In java can I get *.html or a html file with certain text in the name? java.html??
    How you can Help
    US101

    here are the code to list your files
         File startDir = new File("your directory goes here" );
         File[] dirList = startDir.listFiles();
         if (startDir.isDirectory());
         out.print( startDir.getPath() );
              //Start cycling through the array for the file
         for ( int count = 0; count < dirList.length; count++ )
    String fileName = dirList[count].getName();
              int index = fileName.lastIndexOf('.');
              String newString = null;
                   if (index >= 0)
                        newString = fileName.substring(index, fileName.length());
                        if ( newString.equalsIgnoreCase( ".txt"))
                             if ( dirList[count].isDirectory())
                                  out.println( dirList[count].getName() );
                             else
                                  out.println( dirList[count].getName());
                             }//end else
                        }// end if newstring
         }//end if index
         }//end for

  • List all files in a directory on a server that hosts the applet

    Hei :)
    I have a problem. I want to list all files in a directory on my server. ( http://www.foo.bar/tw )
    The applet is in the root folder ( http://www.foo.bar ).
    So i tried it like this
    File fi = new URL(getCodeBase() + "/all/").getFile();But when I try to list the files, I get a SecurityException.
    Can anyone help me out?
    Peace!
    LoCal

    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=&qt=%2Blist+%2Bfile+%2Bserver

  • How to get the path when i select a directory or a file in a JTree

    How to get the path when i select a directory or a file in a JTree

    import java.lang.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import java.awt.HeadlessException;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Iterator;
    * @author Frederic FOURGEOT
    * @version 1.0
    public class JTreeFolder extends JPanel {
    protected DefaultMutableTreeNode racine;
    JTree tree;
    protected JScrollPane scrollpane;
    final static int MAX_LEVEL = 1; // niveau max de descente "direct" dans l'arborescence
    * Sous-classe FSNode
    * @author Frederic FOURGEOT
    * @version 1.0
    private class FSNode extends DefaultMutableTreeNode {
    File file; // contient le fichier li� au noeud
    * Constructeur non visible
    private FSNode() {
    super();
    * Constructeur par initialisation
    * @param userObject Object
    FSNode(Object userObject) {
    super(userObject);
    * Constructeur par initialisation
    * @param userObject Object
    * @param newFile File
    FSNode(Object userObject, File newFile) {
    super(userObject);
    file = newFile;
    * Definit le fichier lie au noeud
    * @param newFile File
    public void setFile(File newFile) {
    file = newFile;
    * Renvoi le fichier lie au noeud
    * @return File
    public File getFile() {
    return file;
    public JTree getJTree(){
         return tree ;
    * Constructeur
    * @throws HeadlessException
    public JTreeFolder() throws HeadlessException {
    File[] drive;
    tree = new JTree();
    // cr�ation du noeud sup�rieur
    racine = new DefaultMutableTreeNode("Poste de travail");
    // cr�ation d'un noeud pour chaque lecteur
    drive = File.listRoots();
    for (int i = 0 ; i < drive.length ; i++) {
    FSNode node = new FSNode(drive, drive[i]);
    addFolder(drive[i], node); // on descend dans l'arborescence du lecteur jusqu'� MAX_LEVEL
    racine.add(node);
    // Gestion d'evenement sur JTree (on �coute les evenements TreeExpansion)
    tree.addTreeExpansionListener(new TreeExpansionListener() {
    public void treeExpanded(TreeExpansionEvent e) {
    // lorsqu'un noeud est ouvert
    // on descend dans l'arborescence du noeud jusqu'� MAX_LEVEL
    TreePath path = e.getPath();
    FSNode node = (FSNode)path.getLastPathComponent();
    addFolder(node);
    ((DefaultTreeModel)tree.getModel()).reload(node); // on recharche uniquement le noeud
    public void treeCollapsed(TreeExpansionEvent e) {
    // lorsqu'un noeud est referm�
    //RIEN
    // alimentation du JTree
    DefaultTreeModel model = new DefaultTreeModel(racine);
    tree.setModel(model);
         setLayout(null);
    // ajout du JTree au formulaire
    tree.setBounds(0, 0, 240, 290);
    scrollpane = new JScrollPane(tree);
         add(scrollpane);
         scrollpane.setBounds(0, 0, 240, 290);
    * Recuperation des sous-elements d'un repertoire
    * @param driveOrDir
    * @param node
    public void addFolder(File driveOrDir, DefaultMutableTreeNode node) {
    setCursor(new Cursor(3)); // WAIT_CURSOR est DEPRECATED
    addFolder(driveOrDir, node, 0);
    setCursor(new Cursor(0)); // DEFAULT_CURSOR est DEPRECATED
    * Recuperation des sous-elements d'un repertoire
    * (avec niveau pour r�cursivit� et arr�t sur MAX_LEVEL)
    * @param driveOrDir File
    * @param node DefaultMutableTreeNode
    * @param level int
    private void addFolder(File driveOrDir, DefaultMutableTreeNode node, int level) {
    File[] fileList;
    fileList = driveOrDir.listFiles();
    if (fileList != null) {
    sortFiles(fileList); // on tri les elements
    // on ne cherche pas plus loin que le niveau maximal d�finit
    if (level > MAX_LEVEL - 1) {return;}
    // pour chaque �l�ment
    try {
    for (int i = 0; i < fileList.length; i++) {
    // en fonction du type d'�l�ment
    if (fileList[i].isDirectory()) {
    // si c'est un r�pertoire on cr�� un nouveau noeud
    FSNode dir = new FSNode(fileList[i].getName(), fileList[i]);
    node.add(dir);
    // on recherche les �l�ments (r�cursivit�)
    addFolder(fileList[i], dir, ++level);
    if (fileList[i].isFile()) {
    // si c'est un fichier on ajoute l'�l�ment au noeud
    node.add(new FSNode(fileList[i].getName(), fileList[i]));
    catch (NullPointerException e) {
    // rien
    * Recuperation des sous-elements d'un noeud
    * @param node
    public void addFolder(FSNode node) {
    setCursor(new Cursor(3)); // WAIT_CURSOR est DEPRECATED
    for (int i = 0 ; i < node.getChildCount() ; i++) {
    addFolder(((FSNode)node.getChildAt(i)).getFile(), (FSNode)node.getChildAt(i));
    setCursor(new Cursor(0)); // DEFAULT_CURSOR est DEPRECATED
    * Tri une liste de fichier
    * @param listFile
    public void sortFiles(File[] listFile) {
    triRapide(listFile, 0, listFile.length - 1);
    * QuickSort : Partition
    * @param listFile
    * @param deb
    * @param fin
    * @return
    private int partition(File[] listFile, int deb, int fin) {
    int compt = deb;
    File pivot = listFile[deb];
    int i = deb - 1;
    int j = fin + 1;
    while (true) {
    do {
    j--;
    } while (listFile[j].getName().compareToIgnoreCase(pivot.getName()) > 0);
    do {
    i++;
    } while (listFile[i].getName().compareToIgnoreCase(pivot.getName()) < 0);
    if (i < j) {
    echanger(listFile, i, j);
    } else {
    return j;
    * Tri rapide : quick sort
    * @param listFile
    * @param deb
    * @param fin
    private void triRapide(File[] listFile, int deb, int fin) {
    if (deb < fin) {
    int positionPivot = partition(listFile, deb, fin);
    triRapide(listFile, deb, positionPivot);
    triRapide(listFile, positionPivot + 1, fin);
    * QuickSort : echanger
    * @param listFile
    * @param posa
    * @param posb
    private void echanger(File[] listFile, int posa, int posb) {
    File tmpFile = listFile[posa];
    listFile[posa] = listFile[posb];
    listFile[posb] = tmpFile;

  • Getting a list of files from a shared directory

    Hi All,
    I need to get a list of files from a shared directory on another server and put them in a HTMLB TableView element with links to the files.
    I was not successful with CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES. This method works in test mode, but gives me a gui_not_supported exception in BSP. I guess BSPs are not allowed to use this.
    Is there any other alternative?
    I need to be able to upload the files as well.
    Thanks,
    Roman
    Message was edited by: Roman Dubov

    Hi again,
    Not sure about the shared directory files list...
    In my opinion, this cannot be done using BSP.
    But, you can try using VBScript to access the file system with object of that sort :
    CreateObject("Scripting.FileSystemObject")
    it is only a thought and you can be sure to cross security problems by accessing files through a Web application...
    Best regards,
    Guillaume

  • List all files in a directory, not including the sub directories if any

    Hi,
    I have been looking around php.net for a bit and can not work
    out how i list the files that are in a directory i.e.
    www.site.com/directory/
    I would like the names of each file to be placed in an array,
    but not to have the sub directories in this list should there be
    any.
    I was given some code a while ago that done this but it
    listed the sub directories and i would like them not in this list.
    I do not have this code anymore and do not know where i got
    it, so i can not get it amended to what i need.
    please can someone tell me what line of code i should be
    using.
    thank you in advance for your help.

    (_seb_) wrote:
    > not very clever wrote:
    >> Hi,
    >>
    >> I have been looking around php.net for a bit and can
    not work out how
    >> i list the files that are in a directory i.e.
    >>
    >> www.site.com/directory/
    >>
    >> I would like the names of each file to be placed in
    an array, but not
    >> to have the sub directories in this list should
    there be any.
    >>
    >> I was given some code a while ago that done this but
    it listed the
    >> sub directories and i would like them not in this
    list.
    >>
    >> I do not have this code anymore and do not know
    where i got it, so i
    >> can not get it amended to what i need.
    >>
    >> please can someone tell me what line of code i
    should be using.
    >>
    >> thank you in advance for your help.
    >>
    >>
    >>
    >
    > The follwoing PHP code will do just that. Just replace
    "pathToFolder"
    > with the path to your folder.
    > I made the list of files also link to each file. Just
    remove the link
    > echo if you don't them to be links.
    >
    > <?php
    > // FUNCTION TO LIST FILES:
    > function listFiles($path){
    > if($handle = opendir($path)){
    > while(false !== ($file = readdir($handle))){
    > if (is_file($path.'/'.$file) &&
    !preg_match('/^\./',$file)){
    > $files_array[]=$file;
    > }
    > }
    > }
    > return($files_array);
    > }
    > $path = 'pathToFolder';
    >
    > // CALL THE FUNCTION:
    > $files_array = listFiles($path);
    > foreach($files_array as $file){
    > echo '<p><a
    href="'.$path.'/'.$file.'">'.$file,'</a></p>';
    > }
    >
    > ?>
    >
    I spotted one error:
    foreach($files_array as $file){
    echo '<p><a
    href="'.$path.'/'.$file.'">'.$file,'</a></p>';
    should be:
    foreach($files_array as $file){
    echo '<p><a
    href="'.$path.'/'.$file.'">'.$file.'</a></p>';
    (a dot after $file, not a coma)
    seb ( [email protected])
    http://webtrans1.com | high-end web
    design
    Downloads: Slide Show, Directory Browser, Mailing List

  • In the topmost Firefox menu with File,Edit,View,History,Bookmarks, I can not get the list of bookmarks to display as they did before. The Bookmarks menu does not open up into the list of bookmarks.

    I am running Mac os 10.6.8 and Firefox 6.0.1 on a MacBook Pro and on a desktop Macintosh.
    The large computer displays a list of bookmarks when you click on the uppermost Bookmarks menu.
    The MacBook Pro displays the following when you click on the Bookmarks word in the top menu:
    "Show all Bookmarks, Bookmark this Page, Bookmark all Tabs and an icon with a blue dot next to Bookmarks Toolbar with an arrow to the right and below that it says Unsorted Bookmarks.
    There is no display of the list of bookmarks from which I can chose as I do on the larger desktop macintosh computer.
    How can I get the list of bookmarks to show as a list when I click the Bookmarks menu?

    A possible cause is a problem with the file places.sqlite that stores the bookmarks and the history.
    *http://kb.mozillazine.org/Bookmarks_history_and_toolbar_buttons_not_working_-_Firefox
    You can also try to move (delete) the Firefox plist file.<br />
    See [http://www.macfixit.com/article.php?story=20060606082246983 How .plist files become corrupt and troubleshooting the results]
    Go to "Library > Preferences" and remove the plist file for Firefox (org.mozilla.firefox.plist).

  • Which WSDL file to get the list of Groups present in OAM.

    Hi All,
    Can any one tell me which WSDL file is to be used to get the list of groups present in OAM from an IDXML call.
    Please provide sample IDXML call if possible.
    Thanks in advance.
    Thanks & Regards,
    Siva Pokuri.

    guys, 80% of my problem got solved.
    here is the solution list as u all have suggested and that i have checked it also.
    RSDCUBEIOBJ     - infocube list for any nav-attr 
    RSDODSOATRNAV  - DSO list for any nav-attr
    ODSOIOBJ. - DSO list for any infoobj
    but in these tables, one thing i observe is that each infocube/DSO name is repeated multiple times. why is that? from where it populate?

  • To display the list of File Name in a report region from a Directory

    Hello All,
    Can any one guide me in displaying the list of file name from a file system directory in a report region with link?
    On click of the link it should display the open/save dialog box.
    I will appreciate the early solution. (It is bit urgent)
    Thanks,
    Shyam

    A quick, "dirty solution would be to have a cron job (I am assuming you are on a UNIX-based system) that populates a file periodically with the names of files in a directory/directories. Then have an external table that points to that file. You can then create an Apex report that lists the contents of the external table.
    1) crontab job:
    ls -1 /source_dir/* > /destination_dir/file.list
    2) create external table:
    CREATE DIRECTORY filedir AS ' destination_dir ';
    GRANT READ ON DIRECTORY xfer_files TO public;
    CREATE TABLE file_list_ext (file_names VARHCAR2(100))
    ORGANIZATION EXTERNAL
    TYPE oracle_loader
    DEFAULT DIRECTORY files_dir
    ACCESS PARAMETERS
    records delimited by newline
    fields terminated by ','
    missing field values are null
    (file_name)
    LOCATION ('file.list')
    REJECT LIMIT UNLIMITED;
    3) create APEX report on table: file_list_ext
    Hope this helps.

  • How do I get Adobe  Photoshop CS to show my Epson 3200 Scanner  in the list under File Import?

    How do I get Adobe  Photoshop CS to show my Epson 3200 Scanner  in the list under File Import?

    That will depend on installing a proper driver for the scanner that is compatible with the respective version of PS. But if you really mean a 12 year old PS CS1, it will be nigh on impossible to get this working with a brandnew scanner... Anyway, you wil lhave to provide more info about your system and clarify the points in question.
    Mylenium

Maybe you are looking for

  • Can I use an app on more than one computer?

    if I buy an app for my mac, can I use it on my powerbook?

  • MouseClicked event = enter key doesnt work

    Hello, when I make some JButoon and add to it MouseClicked event (witch handles some code) everything works fine. But when I mark it with TAB then press ENTER button wont "doClick". So I found out that actionPerformed might be the right handler, but

  • Which group a contact belongs in

    I'm not sure if this question belongs here so apologies up front if it doesn't. It's really a cross product question. I have set up groups in my contact list. I noticed recently that if I add a new contact and don't add it to a group it stays in All

  • How do you remap keys when running windows natively on the macbook?

    I'd like to map the ENTER key on the bottom of the keyboard to the DELETE function so that I will not need to hold down the FN key while pressing the DELETE (backspace) key. Can anyone suggest a way of achieving this? Many thanks.

  • Organizational Management:  Obejct Validity Periods

    Hello Experts, According to the US Best Practices for OM, objects O, C, and S should have validity periods from 01/01/1900 to 31/12/9999.  Since the client has only existed since 1998, the positions will be vacant for decades before they start being