How can I delete a dir which has sub-dir's ?

Dear list,
Can some one send me a link or send me a code example of how to delete all the sub- directories in a specified directory. My dir has sub-directories which contain files!
If I use the java.io package I must loop all the sub- directories, and java.io.File.delete() wont delete a dir when it contains files, so I will have to go into each sub-dir and delete the files before deleting the sub-dir. This is going to be a lot of code, and YES ! I am a little lazy!
Is there a java package, with a method, where I can just delete a dir, which just deletes it and ALL its contents ?
regards
BB

    // Delete an empty directory
    boolean success = (new File("directoryName")).delete();
    if (!success) {
        // Deletion failed
    }If the directory is not empty, it is necessary to first recursively delete all files and subdirectories in the directory. Here is a method that will delete a non-empty directory.     // Deletes all files and subdirectories under dir.
    // Returns true if all deletions were successful.
    // If a deletion fails, the method stops attempting to delete and returns false.
    public static boolean deleteDir(File dir) {
        if (dir.isDirectory()) {
            String[] children = dir.list();
            for (int i=0; i<children.length; i++) {
                boolean success = deleteDir(new File(dir, children));
if (!success) {
return false;
// The directory is now empty so delete it
return dir.delete();

Similar Messages

  • How can i see the URL which has  length more than 255 chars in fucnction

    Hello Every body....
      I am facing one problem....I have a function module which returns URL in one table
      but in the function module display i am able to see only 255 characters,but the URL is more than 255 Characters..How can i see the URL which has the length more than 255 characters..
    In the Table the fields url length is 4000 chars.....
    but display it is showing only 255 chars.....
    Please Help me...??????????

    Hello,
    Have you tried breaking your structure into 255 chunks? I don't know what the structure you are moving from looks like, but you should be able break it back up into the SOLI structure. The end of a line in SOLI doesn't create a Carriage Return/Line Break. You have to insert these yourself like in the following:
    * Create document
          clear mail_line.
          move 'This is a test E-Mail'(d01) to mail_line.
          concatenate mail_line
                      cl_abap_char_utilities=>newline
                      into mail_line.
          append mail_line to l_mailtext.
    What kind of attachment are you wanting to create - a text tab delimited file for reading in a spreadsheet application such as excel? You might try reassembling your data table into a single string with newlines where you need them. Then use function module SCMS_STRING_TO_FTEXT to turn it back into SOLI. This is what I have done in the past. I'm afraid without knowing more about your source structure and attachment type, this is about all I can tell you.
    Vasanth

  • How can we delete the composition which is created by AEGP_CreateComp()?

    Hi,
    I have created a composition using AEGP_CreateComp( ) method under PF_Cmd_SEQUENCE_SETUP command. The composition is displaying in project folder. I have to delete the same composition from project folder under PF_Cmd_SEQUENCE_SETDOWN command.
    we can delete the layer using AEGP_DeleteLayer( ), but how can we delete a composition from project folder which is created by AEGP_CreateComp( )?

    Im getting the crash on 10th line when I delete the composition
         PF_Err err = PF_Err_NONE;
        AEGP_ItemH    item = NULL;
        AEGP_ItemType itemType;
        AEGP_SuiteHandler suites(in_data->pica_basicP);
        err = suites.CompSuite6()->AEGP_GetItemFromComp(compPH, &item);   
        if (item != NULL)
            err = suites.ItemSuite6()->AEGP_GetItemType(item, &itemType);
            if (itemType == AEGP_ItemType_COMP)
               err = suites.ItemSuite6()->AEGP_DeleteItem(item);
    What could be the reason?

  • How can i delete a toolbar that has been added?

    Somehow I have a toolbar for a shop at home site that has been added to my list of toolbars. It takes over my browser when I'm surfing and takes me to places i have not selected. How can i delete this toolbar? I believe I have the latest version of firefox and i am running windows 7

    This sounds like spamware you might have installed by accident. If you go into Add-Ons (Firefox -> Add-Ons) it should be under 'Extensions'. Click the 'Remove' button and that should get rid of it.
    You might also find it under 'Programs and Features' in Control Panel. Remove it if it's there.

  • How can I delete U2 songs which were gifted by Itunes.just cannot get rid of those songs.

    HOw can I delete the U2 songs from my Ipad ,which were gifted  by Itunes ?

    Remove iTunes gift album "Songs of Innocence" from your ...

  • How can I delete the area which I have selected with Pen Tool?

    Hi,
    I have selected the particular area of my background image, which is just complicated. Now, I would like to delete the selection so that I will copy something else in that blank area. How can I delete the selected area?
    Thanks.

    Hobotor wrote:
      Uhm you mean "rightclick---> make selection---> delete "?
    Hi,
    But I can't see such option. Please look below the snapshot:
    I want to remove the existing image (Girl's Image) and insert some other image. Please help.
    Thanks.

  • How can i distill the invoice which has not verified?

    hello evryone:
       my problem is I want to distill the invoice which has not 
       verified through the tcode MIRO.
       thanks in advance!

    Hello,
    Have you tried breaking your structure into 255 chunks? I don't know what the structure you are moving from looks like, but you should be able break it back up into the SOLI structure. The end of a line in SOLI doesn't create a Carriage Return/Line Break. You have to insert these yourself like in the following:
    * Create document
          clear mail_line.
          move 'This is a test E-Mail'(d01) to mail_line.
          concatenate mail_line
                      cl_abap_char_utilities=>newline
                      into mail_line.
          append mail_line to l_mailtext.
    What kind of attachment are you wanting to create - a text tab delimited file for reading in a spreadsheet application such as excel? You might try reassembling your data table into a single string with newlines where you need them. Then use function module SCMS_STRING_TO_FTEXT to turn it back into SOLI. This is what I have done in the past. I'm afraid without knowing more about your source structure and attachment type, this is about all I can tell you.
    Vasanth

  • I am unable to open I cloud with my apple I'd every time I try message comes that " max no of account have been activated on your I pad"  what needs to be done,how can I delete the accounts which I had opened as I don't remember the I'd and passwords

    Can any one help me on this

    It seems that you've been trying to create Apple IDs (even if you thought you were just trying to use one to make an iCloud account) and you have reached the max allowed number of IDs you can create on the device (which is 4 or 5 as I recall). The only way to create yet another one is to use a different device or a computer. No other way around this.
    If on the other hand you want to USE an existing one, go to Settings>iCloud and enter that ID. 

  • How can i measure BAPI runtime which has called from JAVA

    Hi abapers
    how can i get run time for BAPI called from JAVA through JCO.
    i know that i can use SE30 from ABAP by executing from SAP.
    may be ST05 useful for me i did it but when display trace
    i am getting big list by seeing this list i am not able to find the runtime for that BAPI.
    please any one can explain
    reagdrs
    ramesh

    Hi Ramesh,
       Irrespective of whether the call is from an external system or within sap, the bapi will be executed in R/3 only.
    So, you can safely measure the runtime using se30 only.
    If it is taking more time when called from JCo , then you can be sure that the problem is not with SAP and is actually due to the JCo connectivity with R/3.
    Regards,
    Ravi

  • How can I delete a bookmark that has no associated page?

    I have a number of old bookmarks where the page (location) is blank. Bookmarks that follow them do not get displayed in the Bookmarks Toolbar or when I click on "Bookmarks." These bookmarks with missing pages are shown when I click on "Organize bookmarks," but I am not able to delete them.

    See http://kb.mozillazine.org/Locked_or_damaged_places.sqlite

  • How can I delete a purchase (Mavericks) that has not downloaded from my account?

    How can I delete a purchse that has not yet downloaded (Mavericks) from my account? I contacted App Store support and my responder claims to have deleted Mavericks from myaccoount. He didn't; it is still there, under the purchases tab-in the cloud. Thank you.

    Hi Dah-veed
    Thanks for your response. But it doesn't make sense. Mavericks wouldn't download, and although I decided that I wasn't ready for it yet (incompatibility issues), I would like to be ale to get it (OSX) in the future, and if it shows as 'purchased', I won't be able to 'start over' fresh.
    Rachel

  • HT3275 How can I delete a backup of one of my computers from a shared time capsule?

    Hello,
    I have a Time Capsule which is used for backup with Time Capsule by two Macs.
    One of the Macs is currently offline and I want to delete it's backup manually from the Time Capsule.
    This operation takes very long and my impression is, it can not be completed.
    How can I delete the backup which is obsolete to free disk space on the Time Capsule?
    Kind Regards
    Ralph

    The fastest, simplest, and most reliable solution would be to erase the Time Capsule disk. That will only take a few minutes, but you will erase the backups of both Macs when you do this. If you don't mind starting over again on the "other" Mac, that would be the way to go.
    Few of us ever need the backups, especially backups from months and maybe years back, but I understand that it is not easy to think about erasing them and starting over with new backups.
    Deleting an individual backup will take a long time ....that is the way that it is.
    Things will go 4-5 times faster on average, and there will be much less of a chance of an error occurring if you connect the Mac using an Ethernet cable to one of the LAN <-> ports on the Time Capsule for the process.
    Once the sparsebundle file has been deleted, you can disconnect the Ethernet cable.
    I've done this a number of times with no problems. Basically, I setup the file to delete overnight and check the progress in the morning. In every case, the file has been completely deleted when I check.

  • How can I delete large files on my MacBook Pro?

    How can I delete large files on my MacBook Pro? Also my Emails wont delete, how can I delete them?

    Which email client are you using & which version?   Your emails are not appearing in the email trashcan? 

  • How do I uninstall Google Chrome which has stopped working.  I have a MacBook Air 1.6 GHz Intel Core i5 2GB memory

    How can I uninstall Google Chrome, which has stopped working.
    MacBook Air 1.6Gz Intel proccesor @GB memory OS X Maverick

    This helped me. Check it out. Start watching from 1.15
    https://www.youtube.com/watch?v=efnXbn1nC4E

  • HT204150 one of my friend updated her iPhone with my apple id and now her contacts are inside my iPhone , she has deleted my contact which has been i her contact , how can i bring back my contact ?

    one of my friend updated her iPhone with my apple id and now her contacts are inside my iPhone , she has deleted my contact which has been i her contact , how can i bring back my contact ?

    Welcome to the Apple Community.
    The first thing you should do is have your friend log out of your account and change your password.
    Do you have a back up from when you had the contacts on your phone.

Maybe you are looking for