How to see the contents of a directory?

ok, here is my problem. I need to see the contents of a directory (ie. like doing a dir in DOS or ls in Linux) and then process each of the files in the directory.
Is there a way in java to see the contents of a directory? Please help...

hi,
well you can see the contents of a directory, a directory in turn could have files and subdirectories, so you could use the following snippet of code.
import java.io.File;
import java.io.IOException;
public class FileBrowser
     private File mFile;
     public void listDirectory(String fileName)
          mFile = new File(fileName);
          if (mFile.exists()) //check if File or Directory with given name exists
               if (mFile.isDirectory())
                    File mTempFile[] = mFile.listFiles();
                    if (mTempFile.length > 0)
                         for (int i=0; i < mTempFile.length; i++)
                              listDirectory(mTempFile.getAbsolutePath()); //recursive call
               else if (mFile.isFile())
                    printFilePath(mFile);
          else
               throw new IllegalArgumentException("File or Directory does not exist");
     public void printFilePath(File file)
          System.out.println("File path :" + file.getAbsolutePath());
     public static void main(String args[])
          try
               FileBrowser fb = new FileBrowser();
               fb.listDirectory("c://temp//");
          catch(IllegalArgumentException ex)
the above code snippet first figures out if a File object is representing a File or a Directory, if it represents a File it just call a method which prints out the Absolute path of the file which contains the file name also, else if it is a directory it just recursively scans through all sub-directories and files within the directory, also if the String arguement passed to listDirectory is incorrect, it throws a IllegalArguementException, hope this was useful.
Cheerz

Similar Messages

  • How to see the content of an attachment in sxmb_moni

    Hi all,
    Does someone know how to see the actual content of an attachment in sxmb_moni?
    If I look under Inbound Message (CENTRAL)/Payloads, I would see one node for MainDocument and another node with the name of the attachment.
    When I click on the attachment name, a word document shows with one line in it. That line is just the name of the attachment and nothing else.
    How can I see the actual content of that attachment?
    Thank you. Points will be awarded to helpful answers.
    Regards,
    -Michelle

    I checked my coding again in debug mode. I cannot find anything wrong.
    I duplicate here my coding again.
       DATA lo_attachment TYPE REF TO if_ai_attachment.
      lo_attachment  = lo_attachment_protocol->get_attachment_from_binary(
                          data = iv_attachment_content
                          type = iv_attachment_mime_type
                          name = iv_attachment_name
    * set the attachment
      DATA lt_attachments TYPE prx_attach.
      APPEND lo_attachment TO lt_attachments.
      lo_attachment_protocol->set_attachments( lt_attachments ).
    The local variable LT_ATTACHMENTS has field payload-resource with the following expected values --
    KIND : B
    TYPE : application/msword
    BINDATA :  00530068006F00740073005F0073007700630076002E0064006F00630020002000
    The BINDATA correctly contains the dummy data I assigned.
    I must have missed something. Can someone help?
    Best regards,
    -Michelle

  • How to see the content of stored prodecure in sql plus worksheet or sql.plu

    Hi
    i want to see the content of the stored procedure on sql worksheet or sql plus. is there any command for this ?
    please let me know
    thanks

    Hi Anil:
    Following is for SQL*Plus
    If you are logged on to the schema that owns the stored procedure you can issue the following query:
    select text from user_source where name = 'MY_PROG_NAME'
    ORDER BY TYPE, LINE ASC;
    Where MY_PROG_NAME could be the name of a package, procedure or function. Note that when you look at a package source you'll get the specfification and the body listing, in that case you may want to split them into two with following queries:
    spool MY_PROG_NAME.spec
    select text from user_source
    where name = 'MY_PROG_NAME'
    AND TYPE = 'PACKAGE'
    ORDER BY TYPE, LINE ASC;
    SPOOL OFF
    spool MY_PROG_NAME.body
    select text from user_source
    where name = 'MY_PROG_NAME'
    AND TYPE = 'PACKAGE BODY'
    ORDER BY TYPE, LINE ASC;
    SPOOL OFF
    If you are logged on as SYSTEm, you can substitute USER with DBA and look at code for all schemas, however you may need to add OWNER to your query.
    DESC USER_SOURCE
    Name Null? Type
    NAME NOT NULL VARCHAR2(30)
    TYPE VARCHAR2(12)
    LINE NOT NULL NUMBER
    TEXT VARCHAR2(2000)
    DESC DBA_SOURCE
    Name Null? Type
    OWNER NOT NULL VARCHAR2(30)
    NAME NOT NULL VARCHAR2(30)
    TYPE VARCHAR2(12)
    LINE NOT NULL NUMBER
    TEXT VARCHAR2(2000)
    Hope this helps,
    Thomas

  • How to see the content of a website's certificate?

    I was not able to find how to view the content of a website's certificate using the Android version of Firefox.
    On the desktop, this is possible via a 'view' button in the popup which appear when we click on the lock icon near the url bar. On Firefox for Android, I cannot find this button.

    That's exactly what I wanted to point : it is missing.
    I wish it can be added.

  • How to see the contents of jar file?

    Hi
    is there any way we can see the contents of jar file.(Since it is similar to zip file can we unzip it and see the contents)

    In total commander Ctrl + PageDown

  • How to see the content once I submitted the data in the form

    Hi,
    I have used webform editor to create a form and I have embedded some idoc scripts. Once I submitted the data to the content server through the form how will I able to see the submitted data again. Is it possible to see the data in html format...when I open the weblocation of hcsp pag, I can see only title , I am not able to see the title I entered n submitted
    Edited by: user10755799 on Jan 27, 2009 5:14 AM

    I checked my coding again in debug mode. I cannot find anything wrong.
    I duplicate here my coding again.
       DATA lo_attachment TYPE REF TO if_ai_attachment.
      lo_attachment  = lo_attachment_protocol->get_attachment_from_binary(
                          data = iv_attachment_content
                          type = iv_attachment_mime_type
                          name = iv_attachment_name
    * set the attachment
      DATA lt_attachments TYPE prx_attach.
      APPEND lo_attachment TO lt_attachments.
      lo_attachment_protocol->set_attachments( lt_attachments ).
    The local variable LT_ATTACHMENTS has field payload-resource with the following expected values --
    KIND : B
    TYPE : application/msword
    BINDATA :  00530068006F00740073005F0073007700630076002E0064006F00630020002000
    The BINDATA correctly contains the dummy data I assigned.
    I must have missed something. Can someone help?
    Best regards,
    -Michelle

  • FPM - How to see the content of the event raise by FPM event

    Hi All,
         I am trying to locate the view that comes up when we select a medical plan and click on the "Add plan" button in the ESS Benefits Open Enrollment.
    I could not find any view by on click of the "Add Plan" it is calling fpm.raiseEvent(IFPM.EVENT_ADD, BenConstants.VAC_PLANSELECTION);
    How can we look for the code under that class??
    Is there any other way to modify the View other than through NWDS??
    Thanks,
    Sujata

    check here
    Object          FUNC HR_BEN_ESS_RFC_CONF_FORM
    Object Header   FUGR HRBEN00ESS
    FUNC HR_FBN_ESS_FILL_DETAIL_FOR_SEL
    FUGR HRFBN00ESS

  • How to see Manifest content ?

    Hello !
    I want to know how to see the content of the manifest file using the jar.exe command ?
    Is this possible ?
    Thanks
    Best regards
    Ludovic

    Yes:
    jar xf yourfile.jar META-INF/MANIFEST.MF

  • I used Time Machine to recover my Pictures folder. This created a folder called Pictures (original) but I cannot open it.  There is a do not enter roadsign, red disk and white bar on it.  How can I see the contents?

    I used Time Machine to recover my Pictures folder. This created a folder called Pictures (original) but I cannot open it.  There is a do not enter roadsign, red disk and white bar on it.  How can I see the contents?

    Repairing the permissions of a home folder in Lion is a complicated procedure. I don’t know of a simpler one that always works.
    Launch the Terminal application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Terminal in the page that opens.
    Drag or copy — do not type — the following line into the Terminal window, then press return:
    chmod -R -N ~
    The command will take a noticeable amount of time to run. When a new line ending in a dollar sign ($) appears below what you entered, it’s done. You may see a few error messages about an “invalid argument” while the command is running. You can ignore those. If you get an error message with the words “Permission denied,” enter this:
    sudo !!
    You'll be prompted for your login password, which won't be displayed when you type it. You may get a one-time warning not to screw up.
    Next, boot from your recovery partition by holding down the key combination command-R at startup. Release the keys when you see a gray screen with a spinning dial.
    When the recovery desktop appears, select Utilities ▹ Terminal from the menu bar.
    In the Terminal window, enter “resetpassword” (without the quotes) and press return. A Reset Password window opens. You’re not going to reset the password.
    Select your boot volume 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 list the contents of an OSX directory, and output to text file?

    hello there any hints with any known program that does following
    I have recorded my music directory to DVD and now i would like to make an .txt file what the dvd contains...cos its way of hand to write all 100xx files by hand...
    How to list the contents of an OSX directory, and output to text file?
    any prog that does that? any hints?
    best regards

    This script makes a hierarchical file listing all files in a folder and subfolder:
    Click here to launch Script Editor.
    choose folder with prompt "Choose a folder to process..." returning theFolder
    set theName to name of (info for theFolder)
    set thepath to quoted form of POSIX path of theFolder
    set currentIndex to theFolder as string
    do shell script "ls -R " & thepath returning theDir
    set theDirList to every paragraph of theDir
    set newList to {"Contents of folder \"" & theName & "\"" & return & thepath & return & return}
    set theFilePrefix to ""
    repeat with i from 1 to count of theDirList
    set theLine to item i of theDirList
    set my text item delimiters to "/"
    set theMarker to count of text items of thepath
    set theCount to count of text items of theLine
    set currentFolder to text item -1 of theLine
    set theFolderPrefix to ""
    if theCount is greater than theMarker then
    set theNestIndex to theCount - theMarker
    set theTally to -1
    set theFilePrefix to ""
    set theSuffix to ""
    repeat theNestIndex times
    set theFolderPrefix to theFolderPrefix & tab
    set theFilePrefix to theFilePrefix & tab
    if theTally is -1 then
    set theSuffix to text item theTally of theLine & theSuffix
    else
    set theSuffix to text item theTally of theLine & ":" & theSuffix
    end if
    set currentIndex to "" & theFolder & theSuffix
    set theTally to theTally - 1
    end repeat
    end if
    set my text item delimiters to ""
    if theLine is not "" then
    if word 1 of theLine is "Volumes" then
    set end of newList to theFolderPrefix & "Folder: > " & currentFolder & return
    else
    try
    if not folder of (info for alias (currentIndex & theLine & ":")) then
    set end of newList to theFilePrefix & tab & tab & tab & "> " & theLine & return
    end if
    end try
    end if
    end if
    end repeat
    open for access file ((path to desktop as string) & "Contents of folder- " & theName & ".txt") ¬
    with write permission returning theFile
    write (newList as string) to theFile
    close access theFile

  • How can i check messages sent to device through my Verizon account online? i want to open the messages and see the contents.

    How can i check messages sent to device through my Verizon account online? i want to open the messages and see the contents.

        I know it's beneficial to be able to check your message content ArmyQueer. Verizon messages offers a wide variety of convenient options to manage messaging. What make and model device is this? When did you download the application on it? Please be aware you will only be able to see content after the app had been downloaded and installed. Content prior to the app being active will not be available. Here's a link with additional info. http://vz.to/1k3gBxd
    JonathanK_VZW
    VZWSupport
    Follow Us on Twitter@VZWSupport

  • How can i see the content of the cache server 2 ?

    How can i see the content of the cache server 2 ?

    Caching server is backed by an sqlite database.  If you want to see what you currently have downloaded, you can glean some information by accessing the database.  Use this command to connect to the database:
    sudo sqlite3 /Library/Server/Caching/Data/AssetInfo.db
    Once connected, you can use .tables to see the tables in the database but the one with the most information appears to be ZASSET.  Use:
       select * from ZASSET;
    To list the current contents.  You will get a series of records similar to the following:
    26|1|5|0|868991341|402440412.42114|402507221.969799|ffaf18a45cd5dd5e853233629036 5767|30B9108D-ABE4-4061-A2E0-42E91301249B|Fri, 06 Sep 2013 18:21:34 GMT|/content/downloads/14/11/091-9722/ognnjd4fno85m4pbapjtnv23b7rf1mkufx/OSXUpd Combo10.8.5.pkg|
    Note that the final value is a human recognizable name of the package.  However, you may also see items like this:
    125|1|4|0|11622676|406739736.508118|406739736.508125|4f1f9b08b32f9f6211e4569604b 1efef|481BF3D9-99BB-415F-ADB6-860EDD24B08E|Thu, 14 Nov 2013 10:24:30 GMT|/us/r1000/032/Purple6/v4/37/a3/d2/37a3d2f7-2594-8224-7eda-712f17a3fd8b/mzps 6227198657217312566.D2.pd.ipa|
    This is an iOS application.  There is no real way that I know of yet to match the package name (mzps6227198657217312566.D2.pd.ipa) to a product name.
    When finished, type .quit
    R-
    Apple Consultants Network
    Apple Professional Services
    Author "Mavericks Server – Foundation Services" :: Exclusively available on the iBooks Store

  • How do you see the contents of your "Domain" file?

    Thanks to this forum I have found out that the photo files on my Web site are stored in the Domain file under Application Support. How do you see the contents of this file? When I double-click on it, iWeb launches and I see the actual Web site.
    12" PowerBook   Mac OS X (10.4.8)   G4 1.5 GHz, 768 MB RAM

    i don't think it will work. because when you open up the domain file after you changed the size of the pictures, iWeb will probably save again while uploading - so the changes were for nothing. yet i haven't tried it.
    other way is to change them after you published. using graphic converter you just drag all at once in and change all the sizes at once.
    mp

  • How do I see the contents of the hard drive on a Mac Mini?

    How do I see the contents of the hard drive on a Mac Mini?

    Welcome to the Apple Support Communities
    1. Go to Finder > Preferences > Sidebar and tick Hard disks.
    2. Select Macintosh HD in the sidebar.
    See > http://support.apple.com/kb/HT2470

  • TS4403 How can I see the content of my camera roll on the Icloud

    How cn I see the content of my camera roll on the iCloud?

    If you mean the camera roll photos included in your iCloud backup, you can't.   They can only be seen by restoring the backup to your device.

Maybe you are looking for

  • Does the trial version of pse13 work with windows 8.1

    Can someone please tell me if the trial version of pse13 will work with windows 8.1?  I've been trying to download and continue to get error message that "The file archive part is missing."  I have pse 7 and would like to upgrade but want to try it f

  • TOP N analysis with same values

    Dear Members, Suppose we have the following data in the table Student. Sname GPA Jack 4.0 Smith 3.7 Rose 3.5 Rachel 3.5 Ram 2.8 I have seen many questions in this forum which gives good queries for TOP N analysis. But in my case those are not working

  • Error in logs

    Hi i am getting this error frequently in my logs. Though there is no impact on the working of cq5 , i just want to know the reason for this. *ERROR* [ObservationManager] com.day.cq.collab.wiki.impl.WikiServiceImpl Error while accessing repository. ja

  • Cursor taking much longer time

    Is there any solution to optimize this? As it is taking more than 2 hours to update the table. Stats about the table records count: table_1 = 0.3milliions table_2 = 89k table_3 = 2.5 millions table_4 = 6k ========================================= cur

  • System Audio Too Loud On Reboot

    Everything running well with Mountain Lion except one annoying issue. Whenever I reboot the system, the default audio volume changes to the maximum level. Is there a way to control this? Jeff