HELP please in ** Traversing through folders **

Hi,
I have a small java program which when given a particular folder will generate an "index.html" file with "ahref" to all the files and folders in the selected folder.
I have pasted the code below. It uses a small text field and buttons and JFileChooser to allow the user to choose the folder.
I would LIKE TO be able to select the folder and make the code traverse into every subfolder from the seleted folder and generate a "index.html" file in each folder. I would be very grateful for any assistance to help me traverse in folders from.
Many thanks,
Asif
import java.awt.*;
import java.io.*;
import javax.swing.*;
public class IndexGenerator {
private JFrame generatorFrame;
private JPanel generatorPanel;
private JTextField dirField;
private JButton fcButton;
private JButton createButton;
private JFileChooser fc;
public IndexGenerator() {
// Create and set up the window
generatorFrame = new JFrame("Index.HTML Generator");
generatorFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create and set up the panel
generatorPanel = new JPanel(new FlowLayout());
// Add the widgets
addWigets();
// Set the default button
generatorFrame.getRootPane().setDefaultButton(fcButton);
// Add the panel to the window
generatorFrame.getContentPane().add(generatorPanel);
// Display the window
generatorFrame.pack();
generatorFrame.setVisible(true);
* Create and add the widgets.
public void addWigets() {
// Create widegets
dirField = new JTextField("Enter full path here");
fcButton = new JButton("Choose folder");
createButton = new JButton("Generate HTML");
fc = new JFileChooser();
//fc.setCurrentDirectory(new java.io.File("."));
//fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
// Open the File Chooser dialog
fcButton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (fc.showOpenDialog(generatorFrame) == JFileChooser.APPROVE_OPTION) {
dirField.setText(fc.getCurrentDirectory().toString());
} else {
System.out.println("No Selection ");
// Listen to events from the Create button
createButton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// On clicking the createHTML button
createHTML();
// Add the widgets to the container
generatorPanel.add(dirField);
generatorPanel.add(fcButton);
generatorPanel.add(createButton);
* Create the GUI and show it. For thread safety,
* this method should be invoked frmo the
* event-dispatching thread
private static void createAndShowGUI() {
// Nice window decorations
JFrame.setDefaultLookAndFeelDecorated(true);
IndexGenerator ig = new IndexGenerator();
public void createHTML() {
File folder = new File(dirField.getText());
File[] listOfFiles = folder.listFiles();
for(int x=0; x < listOfFiles.length; x++) {
try {
BufferedWriter out = new BufferedWriter(new FileWriter(dirField.getText() + "\\" + "index.html"));
out.write("<HTML> \n" +
"<HEAD><TITLE>Change Requests</TITLE> \n" +
"<STYLE> \n" +
"li,ul {font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif; font-size: 10pt; font-style: strong; color: #000000} \n" +
"h2 {font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif; font-size: 14pt; color: #808080} \n" +
"h4 {font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif; font-size: 8pt; color: #000000} \n" +
"A:link {text-decoration: none ; color: #0000FF; font-size: 8pt;} \n" +
"A:visited {text-decoration: none ; color: #740163; font-size: 8pt;} \n" +
"</STYLE> \n" +
"<BODY> \n" +
"<H2>Change Requests</H2> \n" +
"<UL> \n");
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles.isFile()) {
out.write("<LI><A HREF=\"" + listOfFiles[i].getName() +"\" \"target=\"_blank\">" + listOfFiles[i].getName() + "</A></LI> \n");
} else if (listOfFiles[i].isDirectory()) {
out.write("<LI><A HREF=\"" + listOfFiles[i.getName() +"\">" + listOfFiles.getName() + "/</A></LI> \n");
out.write("</UL> \n" +
"</BODY></HTML> \n");
out.close();
} catch (IOException e) { }
public static void main(String[] args) {
* Schedule a job for the event-dispatching thread:
* creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();

You can make createHTML accept a folder name parameter and know nothing about dirField.getText(). This way you can call the method recursively when you find a directory. The first time you will call it with dirField.getText() of course, and then it will traverse subfolders by calling itself with the found folder name.
HTH
Mike

Similar Messages

  • I downloaded an upgrade to my adobe reader today, and ever since my search engine has switched to yahoo and wont change back to google. I have a macbook pro, help please? Does anyone know how I can change this back? I have tried through my settings but it

    I downloaded an upgrade to my adobe reader today, and ever since my search engine has switched to yahoo and wont change back to google. I have a macbook pro, help please? Does anyone know how I can change this back? I have tried through my settings but it doesnt work

    Hi Timia,
    If you are using Safari as a web browser :-
    Open Safari, go to Safari menu > Preferences > General, and put Google as the homepage. Then, choose Google as your default search engine.
    If you are using Google Chrome as the web browser :-
      Open Google Chrome.
      In the top right corner of the page, click the Chrome menu Chrome menu > Settings.
      In the "Search" section, select Google from the drop-down menu.
    Let me know if you still experience any issue.
    Regards,
    Aadesh

  • I keep getting an error message when I try to log into to ExportPDF through my Adobe Reader. "Network error occurred while attempting to sign in". Can anyone help, please?

    I keep getting an error message when I try to log into to ExportPDF through my Adobe Reader. "Network error occurred while attempting to sign in". Can anyone help, please?

    Hi Simon,
    I'm sorry to hear that you're having trouble logging in to ExportPDF via Reader. I've checked your account, and all is well there.
    For starters, please make sure that you have the most current version of Reader installed by choosing Help > Check for Updates.
    If you're still having trouble logging in via Reader, please try logging in to the web interface at https://cloud.acrobat.com.
    Please let us know how it goes.
    Best,
    Sara

  • I can no longer access Bejeweled Blitz through my facebook account.  I get the message that says, "your browser sent a request that this server could not understand. Size of a request header field exceeds server limit".  Help please.

    I can no longer access Bejeweled Blitz through facebook.  I get the message, "your browser sent a request that this server could not understand. Size of a request header field exceeds server limit". I can access Bejeweled through FB using my husband's log in so to me that suggests the problem is with my log in. Help please.

    Contact FB or use another browser. 

  • Itunes doesn't list all of my recent podcasts. My show is Black Tribbles and it only shows episodes through March 2013, however we do at least two shows a week and they aren't listed. The feed works because the show update to my computer. Help please.

    Itunes doesn't list all of my recent podcasts. My show is Black Tribbles and it only shows episodes through March 2013, however we do at least two shows a week and they aren't listed. The feed works because the show update to my computer. Help please.

    Your feed is at http://blacktribbles.podomatic.com/rss2.xml
    When subscribed to in iTunes the recent episodes show, but the Store hasn't updated for some time.
    There appears to be an issue with the feed. In the episode 'WRESTLING MARCH MADNESS: Final Bracket & Championship' of 31st March you will find in the 'description' tag the following line:
    4. KURT ANGLE
    At the end of this line is an invisible character which seems to be wrecking the feed - although it works OK when suscribing in iTunes it won't load in a browser (and I also found the feed very slow to load, which won't help matters with the Store)
    This sort of thing usually happens when you paste text in from a word processing application and manage to include one of the invisible control characters. I don't know how easy it will be do do it in Podomatic but you should delete that entire line and retype it to remove this charter.
    You should keep an eye on the time it takes the feed to be accessed - if there is a long enough delay (and it was quite some seconds when I tried) the Store may well timeout and fail to read it. At the moment it's showing a cached version from the last time it was able to read it.

  • HT4972 i am not getting notification on most of my apps, e.g twitter and facebook...except i go to the app and refreshed manually. its an iphone 4 and running on ios5...i have gone through everything and its still the same..help please........I seem to be

    i am not getting notification on most of my apps, e.g twitter and facebook...except i go to the app and refreshed manually. its an iphone 4 and running on ios5...i have gone through everything and its still the same..help please........
    I seem to be having the same problem on my brand new iPhone 4S. Everything was working fine on the phone until I updated to iOS 5.1.1, but now I no longer receive push notifications for the native Mail app, Instagram, or the Facebook app. I still seem to be receiving SMS texts and iMessages via push, but the aforementioned apps need to be opened before I can receive missed notifications (having them open in the background seems to make no difference).
    Thanks for any help that you may provide!

    did you try notifications under settings? You can customize it as per your requirement, for each application.
    check this out: http://www.gottabemobile.com/2011/10/12/ios-5-how-to-use-notification-center/ or http://reviews.cnet.com/8301-19512_7-20120625-233/ios-5-notifications-a-deeper-l ook/

  • Little help please regarding deleting files and folders...

    My wife has a MBP and has accumulated some old items in her documents folder that she'd like to delete. She has a USB mouse but the "right click" doesn't appear to work. She's running 10.4.11 and can't reveal the files in icon mode to facilitate dragging to trash. Certainly there is a sequence of keystroke commands that will allow these files to be effectively trashed, but our "control/delete", or "apple/delete", or "option/delete" doesn't do the trick after highlighting the subject file. Help please! TIA!

    To delete a file or folder, high light it then using the keyboard type Command Delete and that will delete it. If you have multiple files and/or folders the same keyboard commands apply.
    Regards,
    Roger

  • Please HELP join these 2 iTunes folders in Windows 7 preserving album artwork & tags (discussion reply requested)

    (Discussion Reply Requested ) Please HELP join these 2 iTunes folders in
    Windows 7 preserving album artwork & "tags"
    I have searched and not found an up to date understandable answer as how
    to join 2 working portable same (apple ID) user iTunes folders into one itunes folder
    while above all else preserving hand edited Abum Artwork and hand edited tags.
    ( It was many hours of hand edited added Album Artwork and editing of tags )
    Situation is Windows 7 ( 64 bit ) with current iTunes installed ( 2014-03-17 )
    The hard drive crashed and the old \iTunes folder and all old contents have been copied and backed up.
    The windows 7 64 bit and latest iTunes 64 bit has been re-installed cleanly ( no old music added )
    Music from the iTunes cloud was then added/downloaded into iTunes
    Now \itunes has 40 gig of music available to play.
    Now I want to join the currently installed working \itunes folder ( 40 gig of music )
    with  the old saved \itunes folder  ( 100 gig of music ) into just one \iTunes folder
    with preserving the current Album Artwork and editing of "tags" of both folders.
    I have seen previous answers that use words like " consolidate " , " export / import ",
    " merge " , " apple home sharing " , " use explorer to copy  ..." , ect
    none of which mentioned if the current Album Artwork
    or tags survive unchanged from their current "specially edited" status.
    I know their may be the ineviatable "duplicates", but there seems
    to be several ways to handle them.  ( If you know the best way to
    prevent or remove duplicates in this situation with joining two
    iTunes folders in Windows please include that information also ).
    Please provide an explanation of how to join these 2 iTunes folders
    in Windows 7 into one \iTunes folder while preserving Album Artwork and tags.

    Mike, thanks for the response. I will try this. I'll have to dig around here too, bc I want to know more about how I can import a windows xml file (while replacing the drive paths) and it creating a seperate itunes library with the pointers on the mac. Essentially, I have 2 libraries and there may not be a way around this with a windows machine and a mac - ive read plenty on Choose library on open, and mac to mac, windows to windows.
    I also need to know more about what is getting stored in the album art folders. I believe it seems that when you select all, and copy the image in the artwork get info page its actually embedding these images in the files themselves, but if you paste into the left bottom artwork display pane its just adding where?? If I deleted the contents of this folder what would happen, should I not be copying this content?
    If I update the images on the mac and swap out the drive paths and move the external drive back to the windows box, will i lose any updates I did while on the mac?
    Good suggestion though, I'll try this out.

  • I manually deleted my iphone photos through windows explorer now it wont sync new music or backup. any help please?

    i manually deleted my iphone photos through windows explorer now it wont sync new music or backup. any help please?

    If those photos were part of the camera roll, they were part of the backup as well and you can restore from the latest backup you made on the old computer. After that transfer the photos to the new PC, follow this article: iOS: Importing personal photos and videos from iOS devices to your computer
    Then sync again to the new one, which will erase the phone again.
    You can also try to copy the backup folder from the old computer to the new one and see if the old backups get recognized, check this article to find the location on your PC:
    Create and delete iPhone, iPad, and iPod touch backups in iTunes
    If the photos were not taken with the phone, your data is gone, photos you sync from iTunes to the phone are not included in the backup.

  • I recently purchased my first MacBook Air but am unable to set up my @live.ie email account. My emails to this account come through to my iphone no problem. Can anyone help please?

    I recently purchased my first MacBook Air but am unable to set up my @live.ie email account. My emails to this account come through to my iphone no problem. Can anyone help please?

    Open Mac Mail.
    From the menu bar click Mail > Preferencees then select the Accounts tab then the Account Information tab then click + to add the account.

  • HT4972 i am trying to download some apps onto my iphone 3gs and it keeps saying i need to update it for this but ive trying and there is no update option on the phone or through itunes, it keeps saying its up to date, can anyone help please?

    i am trying to download some apps onto my iphone 3gs and it keeps saying i need to update it for this but ive trying and there is no update option on the phone or through itunes, it keeps saying its up to date, can anyone help please?

    Would this matter then? can you not update the 3g to the lastest software?

  • HT4623 I have updated my iphone with the current software but it is showing you need to connect to  of itunes to activate your phone, when i did that it is continuously showing an error.please help me to get through.

    I have updated my iphone with the current software but it is showing you need to connect to  of itunes to activate your phone, when i did that it is continuously showing an error.please help me to get through.
    Kindly Activate my phone.

    Rajan Gupta wrote:
    ...it is continuously showing an error.
    See here  >  http://support.apple.com/kb/TS3424
    Also see this discussion.
    https://discussions.apple.com/message/21189708

  • I am running Lion 10.7.2 and I have an external drive hooked to my time machine. I can't rename folders and when trying, I get an error code 8076. The checkbox "ignore permissions for this device" does not show on volume info. Help please???

    I am running Lion 10.7.2 and I have an external drive hooked to my time machine. I can't rename folders and when trying, I get an error code 8076. The checkbox "ignore permissions for this device" does not show on volume info. Help please???

    The TIme Machine volume does not have that checkbox.
    I think the issue is with your Finder...
    Go to Finder "Go" menu hold the option key and choose Library. Then go to Preferences trash these files:
    com.apple.finder.plist
    com.apple.sidebarlists.plist
    Then, restart, or log out and in again.
    (You will have to reset a few finder prefs the way you like them.)

  • All my data on my phone got deleted so I restored it through Itunes and now my IMessage will not recieve nor send out messages through my phone number but my email. I've tried alot but non is really working, help please !!

    All my data on my phone got deleted so I restored it through Itunes and now my IMessage will not recieve nor send out messages through my phone number but my email. I've tried alot but non is really working, help please !!

    Ok. You don't have to select your number. Just check your email under your "grey" number and then at the bottom of this page you will see the option "Start new conversations from". Select your number.

  • Updated to yosemite, now in iPhoto when I try to send a photo I get the following error'Your email did not go through because the server did not reply'. Help please.

    Hi, I've recently upgraded to Yosemite. I tried to send a picture out from iPhoto as I regularly do without issue. Now I get this error message, 'Your email did not go through because the server did not reply'. Can you help please?

    Try rebuilding your iPhoto library. Directions are simple Rebuilding the iPhoto library. Please post back after doing the rebuild and then re-testing.

Maybe you are looking for

  • Text in variable selection

    I have an user entry variable on infoobject, when we run the report on web , on the variable screen , to select the values of the variable/infoobject only key is displayed but the description is not. Though in the properties its made key and text for

  • Error message when trying to upgrade to 9.0

    every time i try to upgrade to the new version for windows vista it always says "invalid drive:F" can someone please tell me what that means?

  • HR Add-on

    Hi Dear where can i find a professional HR(payroll, Insurance,Loan, attendance,..) add-on for SBO- VER 8.8? regards.

  • Using Resource Reference to JavaMail Session Resource

    Hi, Wondering whether someone can give me some helpful pointers to solve the following issue. I have a servlet app, which at some point needs to sent emails. In order to do so, I want to use a JNDI lookup to a JavaMail session resource. Here is a cod

  • Iphone apps are gray

    ever since i updated to iphone os 4.1, my battery icon does not drain, as in it reads it as always being full. also when i try to update or add new apps, it shows them as having a slot, but they are just a gray box. i cannot delete them from the phon