Get directory listing or files contained in a folder which is placed on a s

Hello,
I want to get the directory listing of a particular folder say 'xyz' which is placed on the server.
I am using tomcat. I want to use Http to do it. How do it do it.
Please guide.
Regards,
JAVA_student

JAVA_student ,
as pointed out file list is (in productional environments) usually turned off for security reasons.
But I had a similiar requirement to the one you posted. I had a directory with thousands of image files with the name pattern <id>.jpg and the id's stored in a database. Not for every id in the database there existed a file. I wanted to show an image or in case the image file did not exist a default jpg. I could not set the error pages in web.xml to do it.
So I had to take the id (a parameter in the request to the servlet I wrote for that), had to concat it with the 'virtual' directory name used in the applicationserver for the img directory. Then I had to check the existance of the file and to load it it and display it, if it existed otherwise I had to load and display the default picture.
The problem is similiar to yours as the problem basically is to map a directory in a web application to a real directory in a filesystem (which works for files and directories.
The answer is use getRealPath(String) of the ServletContext-object.
Note: This only allows access to files and directories in the web application.
e.g.
http://www.theserver.com/mywebapp/img/ is a folder containing img files. The server does not allow directory listing.
In a jsp within the application mywebapp you want to show a list of the files in /mywebapp/img/ .
<HTML>
<BODY>
<%
// in a jsp application gives you access to the context
String sRealPath = application.getRealPath("/img") ;
java.io.File fDir = new java.io.File(sRealPath) ;
java.io.File[] allFiles = fDir.listFiles() ;
for (int i = 0 ; i < allFiles.length;i++) {
   String sName = allFiles.getName() ;
%>
<%=sName%><br>
<%
%>
</BODY>
</HTML>

Similar Messages

  • Get a list of files from a folder

    Hi I would like to know how could I get a list of files containing into a folder on my computer using javafx... can anyone help?
    Thank you very much!
    Daniel

    I'll try that... i just want to list all videos containing into a folder intro grid =)
    i thought that had a special way using javafx
    Thanks
    Edited by: skul3r on Dec 19, 2008 6:47 AM

  • 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

  • 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

  • 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;

  • 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

  • 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 a list of files under C:\Program Files?

    dir C:\"Program Files" in DOS will get me a list of files in the directory. But how could I do in Java to get the some results? To put it in two double quotes, does not work.
    Any suggestions?

    Here is a small Java program that will read the contents of any directory for you:
    readDir.java
    ==========
    import java.io.*;
    public class readDir {
       public static void main(String[] args) {
          try {
             String[] dirArray=new File(args[0]).list();
             for (int i=0;i<dirArray.length;i++) System.out.println(dirArray[ i ]);
          } catch (Throwable exception) {
             exception.printStackTrace();
    }Just compile the program and run it as follows:
    java readDir "C:\Program Files"
    ;o)
    V.V.

  • Get directory of a file

    hi, am programing with java applet, and there's a method getDocumentBase() which returns the full URL. however i just need the directory where the file resides, not the file name. i.e., i want
    d:/this/is/the/dir/
    instead of
    d:/this/is/the/dir/applet.htm
    where .htm contains the applet.
    any hints pls? thx alot!

    sory,
    the prob is i want to store some images in another folder rather than the same dir as the html. so for example, the html goes
    d:/this/is/html/
    then i want images in
    d:/this/is/html/images
    and now an applet embedded in the html file needs to read those images, so am wondering how to get the url of the html dir, then attach /images to the end of that so as to get the url of all image files.
    there is a method getImage(URL, String) which seems to fulfil this need however, that only works if all image files reside in the same dir of the html file.
    hope that makes it clear. thx

  • How to send the directory listing and file thru socket?

    I need to know where can i learn the directory listing and sending file thru socket. I m going to develop a simple FTP server/client application..Pls help, thnx!

    Above where you're reading this, and to the right of your screen is a magical little box that, when you type in something like "ftp server tutorial" will take you to a page with some hyperlinks you can click. That little box is used for searching the forum. You can tell this because right above the box, it says "Search Forum". You even have the option of using your <enter> key or the "go" button to begin the searching, once you've typed in your criteria, of course. Pretty handy, huh? Well, I won't keep you any longer. Go ahead, give it a shot. It doesn't hurt, and you might actually get some valuable results for the minimum amount of effort you're apparently willing to exert.

  • How to get a list of file paths for all files used in a project

    I have a project in Premiere Pro CC which has a large number of bins.  A sequence in one of these bins uses files from other bins.  I am trying to find the locations of all each of the files used  in the project.
    1)  Obviously I can select each clip in the timeline and show in finder, but there a lot of clips
    2) The video usage associated with each file in the project would help.  However
               1.  I haven't found a way to display only clips that have video useage if all of the bins have not been expanded.
              2.  Video usage  shows usage for all sequences, so one would have to manually check the pull down for each file to see if it is used in the sequence in question.
    3) I tried exporting the project to final cut pro xml.  The path url gives me the information that I need.  For some reason, however, when I do the export only one clip's information is there, not the information for all of the other clips in the project.
    4) I tired an export for speedgrade and all of the file names are there.  However the paths are not. 
    Basically I want to find all of the files in the project and relocate them to a specific folder for that project.  There's got to be a way to do this but I'm not seeing it ....

    Thanks for the suggestion concerning the file path.  And certainly it would have been nice to have done this before beginning.  However this is a project that has been around for quite a while, and the files have been moved into different bins.  And now the project sequence is being revised.
    So the problem is, worded slightly differently, how can I search all of the bins for the files that are used just by this sequence, ignoring the files which are used by other sequences?  Or, how can I get a list of the file paths of the files that are used in the sequence?

  • 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 file names in to a new folder?

    Hi,
    Does anyone know if there is a way of having a list of  image file names, searching for the images then putting them into a new folder?  I'm guessing it can probably be done through mac scripting but I know nothing about scripting and genreally not great with technogy so ideally need step by step instructions!!
    If anyone can help I would really appreciate it!!
    Ruth

    Without details about your workflow and folder set up, I can only give you a generic script, but this should at least get us started.  test it and see what needs to be tweaked.
    -- set paths to source and destination folders
    set imageSourcePath to POSIX path of (choose folder with prompt "Choose a source folder.")
    set destinationFolder to POSIX file POSIX path of (choose folder with prompt "Choose a destination folder.")
    -- get file names from text file: assumes one name per line.
    set fileNameTextFile to (choose file with prompt "Choose a file list text file." of type "public.plain-text")
    set fileNames to paragraphs of (read fileNameTextFile)
    repeat with thisFileName in fileNames
      -- replace each file name with an alias to that image file
              set contents of thisFileName to POSIX file (imageSourcePath & thisFileName)
    end repeat
    tell application "Finder"
      -- using 'duplicate' because I assume you want to make copies rather than move files
      duplicate fileNames to destinationFolder
    end tell

  • Getting a list of File Sharers in Tiger

    Is there a way to get a list of the computers connected through file sharing? One of my computers is set as a mini server running regular Tiger. There are only 10 connections allowed through file sharing and I keep maxing out.
    I do not have ten macs that are connected in my department and was wondering if there was a way to see what other machines are connected?
    I know you can do it with OS X Server but I really would like to not have to spend $1000 on a OS X Server license. Are there any third party programs that show this or way to use terminal to look at them?

    http://discussions.apple.com/thread.jspa?messageID=9169364&#9169364

  • Urgent - How to get Default list of file handlers

    Hi.
    I have mad a small application in java
    It has a Jlist and a button.
    When the button is clicked it shows a file dialog.The file that the user selects from the dialog is listed in the Jlist.
    When the user rightclicks on the JList it shows a popupmenu with a "Open" menu item which when clicked the file is opened by its default opener ie, like .doc files opened in word.
    However if the file is not recognized in windows then i want to popup the list of programs from which the user can select the program he wants to open the file with..
    How can that be done??
    Waiting for the reply
    Pinju

    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

Maybe you are looking for

  • Trying to install 5.1 on older system.

    Hi all. I'm working on a client's machine and he's just bought Tiger and FCS 5.1 for it. The machine is a bit of a legacy machine, it's a 450mhz DP G4. Tiger is on and everything is updated to the latest versions and he also has FCP 4.5 on it. I know

  • Blackberry z10 - no messages in business hub

    Hello Community, I just received my blackberry Z10 phone and I have to say it is very very nice to use. It´s working threw our company server, and I use the company e-mail on it. The only big issue I have is that if I´m in the business hub, I do not

  • Many versions of E71: -E71-1/E71-2 and E71-3? - H...

    Hello. I have been informed that there are 3 versions of the E71 E71-1 RM-346 = GSM 850/900/1800/1900; WCDMA 900/2100 E71-2 RM-357 = GSM 850/900/1800/1900; WCDMA 850/1900 Este es el que usamos E71-3 RM-407 = GSM 850/900/1800/1900; WCDMA 850/2100 E71

  • Import datas alone from the dumpfile

    Hi DBAs, I have a dumpfile, which includes 500 tables structure & datas too. I am using oracle 11g- Normal export, In my new schema i have imported 500 table structure alone from the dumpfile. Here my question is that, out of 500 from the dumpfile, I

  • Why won't my iPhone 4 connect to iTunes

    I'm trying to connect my iPhone 4 to iTunes through my computer but everytime I plug it in, iTunes freezes and won't do anything. I end up having to ctrl+alt+del to close it down. Earlier it was saying that there was something wrong with the syncing