CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2009
    Posts
    4

    Unhappy List all the files and subdirectory in jtable

    I had faced the problem where I cannot list the content in jtable..as I would like to list out all the files, subdirectory and its last modified in that table… help…


    // gets the sub files of a folder
    public ArrayList<File> getSubs(File dest) {
    File[] subfiles = dest.listFiles();
    ArrayList<File> subFolders = new ArrayList<File>();
    // if subfiles is null, it means that listFiles() didnt return anything,
    // so we are dealing with a file, not a folder
    if (subfiles != null)
    // all teh contents of the folder are added to the array list
    for (int i = 0; i < subfiles.length; i++) {
    subFolders.add(subfiles[i]);
    }
    else
    // otherwise we jist add the file to the list
    subFolders.add(dest);

    return subFolders;
    }

    public Object[][] getFileStats(File folder){

    ArrayList<File> folderList = new ArrayList<File>();
    // first we add all the contents of the folder that we want to scan to
    // the folderList
    folderList.addAll(getSubs(folder));

    //File[] list1= folder.listFiles();
    Object[][] results = new Object[folderList.size()][header.length];

    for (int i = 0; i < folderList.size(); i++) {

    long modTime = folderList.get(i).lastModified();
    Date d = new Date(modTime);

    if (folderList.get(i).isDirectory()) {
    // if its a directory, we get all its subfolders/files and add them to the folderList
    folderList.addAll(getSubs(folderList.get(i)));

    results[i][0]= folderList.get(i);
    results[i][1]= d.toString();
    }

    }
    return results;
    }

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: List all the files and subdirectory in jtable

    When posting code, please put it between CODE tags so it remains readable.

    I can't see JTable used anywhere in that code - exactly what is the problem?

    The sooner you start to code, the longer the program will take...
    R. Carlson
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured