DELETE() method..need help!!

private void deleteAll(){
File file;
String from = "C:/A/";
try {
file = new File(from);
} catch (Exception e) {
file = null;
e.printStackTrace();
if (file != null) {
String files[] = file.list();
for(int x = 0; x < files.length ; x ++){
File f = new File (files[x]);
if(f.isFile()){
f.delete();
}else{
System.out.print("WHAT PROBLEM?");
} else {
System.out.println("no such url");
} I wish to delete all files in C:/A/ when running this method..So anyone can find out what problems with my code..Thanks
Edited by: kahleong888 on Jun 14, 2008 9:06 PM

Kah,
To "prune" a whole directory and it's contents you need to depth-first-recurse the tree, (logically) pruning the branch you are standing on the way back up the tree... and if you (logically) recurse a "directory tree" from the "root" at the top... down to the "leaves" at the bottom, then shouldn't "trees" be called "roots" instead of "trees"... Hmmm... Just one of those things.
It goes something like this:
package forums;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
class Pruner
  public static void main(String[] args) {
    String top = args.length>0 ? args[0] : "C:/tmp/test/directoryToPrune";
    try {
      long start = System.currentTimeMillis();
      int n = prune(top);
      long took = System.currentTimeMillis()-start;
      System.out.println("Removed "+n+" objects from "+top+" in "+took+" milliseconds.");
    } catch (Exception e) {
      e.printStackTrace();
  private static int prune(String dirName)
    throws FileNotFoundException, IOException
    File dir = new File(dirName);
    if ( !dir.exists() ) {
      throw new FileNotFoundException("Not found: "+dir.getCanonicalPath());
    return recursivePrune(dir);
  private static int recursivePrune(File dir)
    throws FileNotFoundException, IOException
    String fullname = dir.getCanonicalPath();
    int count = 0;
    if ( dir.isDirectory() ) {
      for (File file : dir.listFiles()) {
        count += recursivePrune(file);
      // having removed dir's contents we continue and remove dir.
    // if dir isn't a dir then it must be a SINGLE file, soft-link, named-pipe...
    if (!dir.delete()) {
      throw new IOException("Failed to delete file: "+fullname);
    return count+1;
}I recommend you move the prune(String dirName) method (and it's recursivePrune(...) helper method) to an abstract utilz class (something like $yourInitials.utilz.io.Dirz), and make it public of course.
Cheers. Keith.

Similar Messages

  • I need help installing microsoft silverlight on my macbook pro. i deleted it and redownloaded it but i cannot install it on my macintosh hd disk, because it says it is already somewhere else on the computer after i deleted it. need help!

    Hi i need help installing micrsoft silverlight it just wont install because of errors

    Removing Silverlight - MAC | Microsoft Silverlight

  • Switch method need help please ;-(

    Hello, I am having trouble with this switch method. I have yet ot construct the AirplaneList object "plane". For I have yet to be taught about it properly
    Can someone at least help me with the switch incident. I have learnt how to make a menu for the user to input the letters A-F in uppercase and lower case. However I am unsure on how to associate "case a" to the method
    //add Airplane
    public static void option1 (AirplaneList plane)
    ? I can get it to print out "case a" continueosly, but how to I associate it to the method. I am aware that the AirplaneList will be a class I have to define earlier, and that "plane" is an object I will need to intiate. If anyone will be willing to help me construct this part of the code I can award them Duke dollars.
    as far as I can tell the constructor method would start off like
    AirplaneList plane = new AirplaneList;
    ok? then what do I do?
    do I define its methods then?
    plane.add()
    Ok well this is the majority of the code I have already.
    import javax.swing.JOptionPane; //indicates that the compiler should load class JOptionPane for use in this application.
    public class AirplaneListT
         public static void main (String[] args)
    throws java.io.IOException
              char choice; //Words choice and size are the names of variables
         //     int size; //This declaration specifies that the variable are of data type char and int
         //     size = EasyIn.getInt(); // Converts size from int to something?
         //Char - a variable that may only hold a single lowercase letter, a single uppercase letter, a single digit or a special character
    //(such as x, $, 7 and *)
         // The code below creates a dialog box for the user to input a choice
         String inputcode;
         inputcode = JOptionPane.showInputDialog("A: add an airplane from the list\n" +
                                  "B: remove an airplane from the list\n" +
                                  "C: check if the list is empty\n" +
                                  "D: check if the list is full\n" +
                                  "E: display the list\n" +
                                  "F: quit\n" );
         JOptionPane.showMessageDialog(null, "You have chosen choice " + inputcode);
    //The null first argument indicates that the message dialog will appear in the center of the screen. The 2nd is the message to display
    do
         // get choice from user
         choice = inputcode.toUpperCase().charAt(0);
              System.out.println();
              //process menu options
              switch(choice)
                   case 'A':
                   case 'a':
                        JOptionPane.showMessageDialog(null, "Case " + inputcode);
                        break;     //done processing case
                   case 'B':
                   case 'b':
                        JOptionPane.showMessageDialog(null, "Case " + inputcode);
                        break;     //done processing case
                   case 'C':
                   case 'c':
                        JOptionPane.showMessageDialog(null, "Case " + inputcode);
                        break;     //done processing case
                   case 'D':
                   case 'd':
                        JOptionPane.showMessageDialog(null, "Case " + inputcode);
                        break;     //done processing case
                   case 'E':
                   case 'e':
                        JOptionPane.showMessageDialog(null, "Case " + inputcode);
                        break;     //done processing case
                   case 'F':
                   case 'f':
                        JOptionPane.showMessageDialog(null, "Case " + inputcode);
                        break;     //done processing case
                   default:
                        JOptionPane.showMessageDialog(null, "Invalid entry!");
                        break;     //done processing case
         }while (choice!= 'F' || //end AirplaneList tester
         choice!= 'f' );
    //add Airplane
         public static void option1 (AirplaneList plane)
              String flight;
              flight = JOptionPane.showInputDialog("Please enter airplane filght number" );
              //create an Airplane object to add to list
              Airplane flight = new Airplane();
              //add string to list if the list is not full
              //access the 'add(Airplane)' method from the AirplaneList class;
              //if the list is full, return a statement to the user indicating that no more plane can be added onto the list
         //remove airplane
         public static void option2 ()
              //get position of item
         string enterpos;
         enterpos = JOptionPane.showInputDialog("Please enter position to remove" );
              System.out.print(":")
              int plane = Easyln.getint();
              // delete item if it exists
              //access the 'remove(Airplane)' method from the AirplaneList class;
              //if the user enter an invalid number for the position, returen a statement
              //indicating that there is no such posititon.
         //check if empty
         public static void option3 (AirplaneList plane)
              if (plane.isEmpty())
                   JOptionPane.showInputDialog("list is empty" );
              else
                   JOptionPane.showInputDialog("list is not empty" );
         //check if full
         public static void option4 (AirplaneList plane)
              if (plane.isFull())
                   JOptionPane.showInputDialog("list is full" );
              else
                   JOptionPane.showInputDialog("list is not full" );
         //display list
         public static void option5 (AirplaneList plane)
              if (plane.isEmpty())     //no need to display if list is empty
                   JOptionPane.showInputDialog("list is empty" );
              else
                   JOptionPane.showInputDialog("Airplanes in list are" );
                   //loop through list
         System.exit(0); //Terminates the program

    case 'A':
    case 'a':
    JOptionPane.showMessageDialog(null, "Case " + " + inputcode);
    break;     //done processing case
    ok are u saying if i invoke a method i go something
    like this?
    case 'A':
    case 'a':
    JOptionPane.showMessageDialog(null, "Case " + " + inputcode);
    AirplaneList.option1(); //Tell Airplanelist to add                    
    break;     //done processing caseIn both cases, you're calling methods. In the latter case, you're calling two methods.
    What's the problem exactly? What part are you having trouble with?
    ... so that then when case a is activated it should go
    onto option1 method?That's one thing you can do, yes. I don't know if you should do it. It depends on what your program needs to do.
    //add Airplane
         public static void option1 (AirplaneList plane)
              String flight;
    flight = JOptionPane.showInputDialog("Please enter
    r airplane filght number" );
              //create an Airplane object to add to list
              Airplane flight = new Airplane();
              //add string to list if the list is not full
    //access the 'add(Airplane)' method from the
    e AirplaneList class;
    //if the list is full, return a statement to the
    e user indicating that no more plane can be added onto
    the list
         }OK, this looks odd. Is this what you're having trouble with?
    BTW, I'd strongly suggest making a stronger separation of application code from GUI code.

  • I deleted bootcamp need help

    Ok I just got a new I Mac this weekend (Firsst Mac ever :D) and I deleted bootcamp but now I need it back but I emptyed my Trash and now can't find it so I need to get an installer for bootcamp. I can't find it on OS X's disk 1 or 2 so I need an installer. If anyone could help it would be great

    Welcome to Apple Discussions:
    I believe it's on disk 1, under optional bundles or packages.
    You can also use Pacifist to recover it
    http://www.versiontracker.com/dyn/moreinfo/macosx/12743
    Or use the information on the following page
    http://support.apple.com/kb/TS1889?viewlocale=en_US
    Message was edited by: nerowolfe

  • Methods - Need Help!

    Please help with the following question...
    Describe the structure of a typical method making reference to its accessibility, return value, passed parameters, its begin/end delimiters and the method call itself:
    public void paint (int x, int y) {
    paint(100, 100);
    Explain the benefits of encasing a block of software code within a method.
    Yours faithfully

    ok, so i take it that you are not pleased that i
    answered an obvious homework question.No, I just thought it was funny that he posted a question that sounded like he copied it verbatim from a homework assignment. So my joke was to post a question that sounds even more like a verbatim copy. Hahaha.
    Re: helping students, I think it's appropriate in many cases. For example, when you're starting out it's easy to get tripped up on minor syntactical issues, and there's really no harm in pointing out errors like that.
    Basically everything in computer science is arbitrary. That's the cool thing about it. But this also means that a beginner can be terribly lost, since for a given problem he may not know where to even start looking for information ... intuition can be frustratingly useless in many cases. It's always appropriate to tell someone what things are called and what terms they should be looking up in their manual. There's no shame in not knowing these things.
    Also, if my experience was at all typical, college professors, and even TA's, can be annoying remote, unavailable, unhelpful, and even smug. (I've known profs and TA's who seemed to feel that if you asked them a question, then you weren't "cluefull", and therefore you didn't deserve to know the answer and by the way they're better than you. A friend of mine had to deal with a prof who informed him that he had to know a particular issue to pass the class, but he refused to teach it in class or even suggest references for independant study.) This wouldn't be so bad if the profs could write well so that all you were left with were a lot of footwork to do, but many profs can't be bothered to write their assignments in complete sentences or check for typos. Given that environment, I think it's fine if someone posts a opaque homework question and asks if someone can explain what it means exactly, for example.
    I think the rule of thumb is that you want to encourage and reward natural curiosity, but not make things so easy that curiosity is never exercized. Maybe I'm saying this because I'm getting paternal in my old age.

  • IPad2 memory full of photos, can't delete. Need help, please!

    My iPad2 memory is full of photos because of the mistakes I made when downloading pictures from my camera. Pictures have been downloaded multiple times, plus video from my camera and I videoed a recent family reunion for my dad, who is no longer able to travel and see his family. When I tried to sync my iPad through my pc on iTunes it had errors and did not update. Then I started getting messages on my iPad that my memory was full and I needed to delete photos and videos.
    I was able to go to photos, select the arrow on the top right, which gave me the delete option and could select pictures which were downloaded on my iPad and delete them. After deleting about 40 pictures, the delete button no longer worked and I can't get it to work again. I have turned off the iPad, selected one pic at a time, several pics, everything I can think of, but no luck. Does anyone have any advice for me? I would be very grateful for your input.

    If the Reset doesn't work, try a Restore.  Note that it's nowhere near as quick as a Reset.  From iTunes, select the iPad/iPod and then select the Summary tab.  Follow directions for Restore and be sure to say "yes" to the backup.  You will be warned that all data (apps, music, movies, etc.) will be erased but, as the Restore finishes, you will be asked if you wish the contents of the backup to be copied to the iPad/iPod.  Again, say "yes."

  • Deletion query need help

    Prg
    CASE SY-UCOMM .
        WHEN 'SAVE'.
          REFRESH IT_CURR.
          LOOP AT G_TC_VALUE_ITAB INTO G_TC_VALUE_WA .
            MOVE-CORRESPONDING G_TC_VALUE_WA TO IT_CURR .
            IT_CURR-POSNR = GV_POSNR .
            IT_CURR-VBELN = GV_VBELN .
            APPEND IT_CURR .
          ENDLOOP .
          DELETE IT_CURR WHERE ZWMENG_CPD EQ 0.
    LOOP AT IT_CURR .
            TOTAL = IT_CURR-ZWMENG_CPD + TOTAL.
          ENDLOOP.
          IF TOTAL > GV_KWMENG.
            IF SY-SUBRC EQ 0.
           MESSAGE ID 'Z1' TYPE 'I' NUMBER '222' WITH 'Order Qty > CPD Qty'.
             LEAVE TO SCREEN 100.
            ENDIF.
          ENDIF.
          CLEAR G_TC_VALUE_COPIED.
          LEAVE TO SCREEN 0 .
        WHEN 'CANC'.
          CLEAR G_TC_VALUE_COPIED.
          LEAVE TO SCREEN 0 .
      ENDCASE .
    1)it_curr which contain the dynamical inputted values
    eg 1000
    1000
    total 2000 over
    if i input 500 and 1000 after saving button on the top
    now total contents is
    1000
    1000<----
    after this delete val
    500 <--- delete all consc val
    1000 <---
    2)GV_KWMENG contain 2000 value
    3) from it_curr i calculate
    TOTAL = IT_CURR-ZWMENG_CPD + TOTAL.
    4)
    againing loop with condition total > than gv_kwmeng
    5) delete the concecutive value after condition is true

    If I use following query
    SELECT DISTINCT STAGE_1_MG_CLIENT.CLIENT_ID, STAGE_1_MG_CLIENT.BIRTH_DT, STAGE_1_MG_CLIENT.ETHNIC_CD, STAGE_1_MG_CLIENT.GENDER_CD, STAGE_1_MG_CLIENT.MEDICARE_NUMBER, STAGE_1_MG_CLIENT.MEDICARE_YN, STAGE_1_MG_CLIENT.ALIAS_YN, ltrim(rtrim(STAGE_1_MG_CLIENT.SAVERR_NAME)), STAGE_1_MG_CLIENT.SSN, STAGE_1_MG_CLIENT.TERMINATION_CD, STAGE_1_MG_CLIENT.TPL, STAGE_1_MG_ENROLLMENT.CLIENT_ID, STAGE_1_MG_ENROLLMENT.SERVICE_GROUP_CD, STAGE_1_SAVERR.CLIENT_ID, STAGE_1_SAVERR.SSN, STAGE_1_SAVERR.STAT_2, STAGE_1_SAVERR.STAT_3, STAGE_1_SAVERR.STAT_4, STAGE_1_SAVERR.STAT_5, STAGE_1_SAVERR.STAT_6, STAGE_1_SAVERR.MEDICAID_BENEFITS_close_DT, STAGE_1_SAVERR.ACTION FROM STAGE_1_SAVERR, STAGE_1_MG_ENROLLMENT, STAGE_1_MG_CLIENT where STAGE_1_MG_CLIENT.CLIENT_ID = STAGE_1_SAVERR.CLIENT_ID (+) and STAGE_1_MG_CLIENT.CLIENT_ID = STAGE_1_MG_ENROLLMENT.CLIENT_ID (+) and STAGE_1_MG_ENROLLMENT.SERVICE_GROUP_CD(+) in ('2','3','12','13','14','15','16','17','18')
    I get the following error message
    Error at Command Line:1 Column:892
    Error report:
    SQL Error: ORA-01719: outer join operator (+) not allowed in operand of OR or IN
    Thanks,
    Jay

  • Hi I need help please .... I have my credit card information in my account ... But I wanted to delete

    Hi I need help please .... I have my credit card information in my account ... But I wanted to delete &amp; I like too add a App Store card

    Hi, Ajchenicholas. 
    Credit cards attached to an Apple ID can be removed and payment method changed to none as long as there is not an outstanding balance.  The article below will walk you through this process. 
    iTunes Store: Changing account information
    http://support.apple.com/kb/ht1918
    You can always add an iTunes Gift Card to your account at any time.  Here are the steps that will walk you through adding an iTunes Gift Card. 
    iTunes Store: How to redeem a code
    http://support.apple.com/kb/ht1574
    Cheers,
    Jason H.

  • Need help, MMC tree got deleted, very urgent.

    Hi,
    My sap MMC tree, got deleted in the server. I have been trying to restore since 2 days and couldnt succeed, please help me.
    1) i have uncared the sapmmc.sar from   Kernal\NT\I386\MMC\sapmmc.sar file
    2) i got about 7 files, in which there is one sapmmc file i have tried to double click it, n check but no go.
    3) i also tried to run the Sapstartsrv.exe file and fill in up the values in pop up window. & filled up the following values :-
                        SID: DEV
                        NR: 00
                        StartProfile:  (entire start profile path given)
                        user: devadm
                        passwd; (given)
    - but it says "the account name is invalid or does not exist or the password is invalid for account name specified"/
    - no go in both the cases.
    Please need help very urgent.
    Regards,
    Satish.

    siva,
    I am getting same error since 2 days
    SID: DEV
    NR: 00
    Start Profile: (entire start profile path)
    User: <hostname>/devadm
    passwd: ****
    Error:
    cannot install service
    create service failed:421
    The account name is invalid or doesnot exist, or the passwd is invalid for the account name specified.
    Edited by: satish c on Jun 4, 2008 11:12 AM

  • I sync my iPad. Now everything is messed up playlists and music are gone. Weird stuff showed up. And now I can't find the option to delete or make new playlists. 6.1.2 is my newest version!! NEED HELP!!

    So I don't sync my iPad very often. My dad and I share a computer. And I decided to do it the other day. I am pretty sure I did it all correctly selecting music that I wanted not deleting playlists but it seems to be that they are gone. And music I didn't want has appeared. And now I don't have an option (with this new iOS 6.1.2) to make new playlists or edit music I don't want out.
    I know I need help figuring those two things out 1 how to make a play list. There isn't a "add" button anymore in that screen I have a "you have no playlist"with a button underneath that says "go to iTunes Store" why I would need the store for that, I do not know.
    Then in the songs, artists, albums sections where you used to be able to hit "edit" button to delete the music you have that you don't want. I don't seem to be able to do anything at all to get rid of the random music I have.
    I need help. I know my iPad fairly well but I am not super savvy with it either.

    Is there a "New" button at the top right of the Playlists section of Music?
    There is no Edit button to delete music, swipe sideways on the song to reveal the delete button. Tap and hold on the artwork in Artists and albums to reveal the (X) button to delete. Or connect the iPad back up to iTunes on the computer and check your sync settings for music to ensure you are syncing the right content.

  • How can I delete my old iCloud account cause I forgot my password and my email has been block. Please I need help urgently

    How can I delete my old iCloud account cause I forgot my password and my email has been block. Please I need help urgently

    Contact the Apple account security team for assistance resetting your password: Apple ID: Contacting Apple for help with Apple ID account security.

  • This sign appeared in my account: "Your payment method was declined. Update your biiling info'. After adding new information about my others cards I see the same sign. Can't understand what the problem is and what should I do. Need help!!!

    This sign appeared in my account: "Your payment method was declined. Update your biiling info'. After adding new information about my others cards I see the same sign. Can't understand what the problem is and what should I do. Everything used to be good before.
    Do anyone know what I supposed to do in that situation?
    Really need help!
    Thanks in advance.

    Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • I need help on my MacBook Pro. Recently I've deleted another partition of my disk from the disk utility and I found out that my disk capacity wasn't get into the normal one which is 750GB. Meanwhile I installed window 7 into the partition disk.

    I need help on restoring my disk capacity back to normal. I installed window 7 into the partition disk through bootcamp and I deleted it from disk utility. After I erase the partition disk,I get my capacity to 499GB but not 750GB. Do I need to reinstall my MacBook or something to do with the restoring?

    Welcome to the Apple Support Communities
    Rodney Lai wrote:
    I installed window 7 into the partition disk through bootcamp and I deleted it from disk utility
    You shouldn't do it. You have to erase the Windows volume with Boot Camp Assistant, so it will restore the space onto the OS X volume and that volume will have 750 GB.
    As you did it with Disk Utility, you have to resize your OS X partition manually:
    1. Open Disk Utility, select your hard disk at the top of the sidebar, and go to Partition tab.
    2. You will see a bar with Macintosh HD. You have to click it at the bottom right corner and drag it to the end of the bar, so Macintosh HD will use all the space of the hard drive, and press Apply.
    3. Close Disk Utility and your OS X partition will have 750 GB

  • I dont know how i got my photos to my ipod touch from my pc and now i wanna delete them but couldn't. so need help. please let me know.

    i dont know how i got my photos to my ipod touch from my pc and now i wanna delete them but couldn't. so need help. please let me know.

    To turn off auto sync - launch iTunes and go to Edit>Preferences>Devices - check the box at the bottom that says - Prevent iPod, iPhones and iPads from syncing automatically. Click OK and then quit iTunes.
    Connect your iDevice to your PC.
    Launch iTunes,
    Click on the device name on the left side of the iTunes Window.
    Click on the Photos Tab in the iTunes window on the right.
    Untick all of the photos or albums that you want to remove.
    Click on Apply in the lower right corner of iTunes
    If you untick or uncheck the Sync Photos heading and then click Apply it will remove all of the photos from the device when it syncs. In this screenshot - I have only certain albums and events selected to sync.

  • Please i need help to how to recover my camera roll photos i deleted them yersterday by accident im need with the ipod and i took the pictures with ipod but i want to know how to recover my photos in a easy fast FREE way as soon as porssible pleasse???

    please i need  help to how to recorver my cameral roll photos from my ipod in a easy FREE way as soon as possible

    Restore from backup if they are in a backup. Otherweise I know of no free way. These are paid and no one has said that they worked.
    iPhone Recovery Stick - recover deleted text messages & more
    Recover files from iPod Touch | Restore data iPod | iPod touch undelete, unformat

  • Need help deleting graphic junk mail

    I need help. I cannot delete graphic junk mail into trash. When I try it says unable to move messages. Messages could not be moved to mailbox trash. And the dial keeps spinning. I'm not getting mail cuz this junk is bogging down my iPad &amp; iPhone.
    Any suggestions would be greatly appreciated. I tried going on my MAC and deleting but they dont show up there?!? I tried rebooting, hard reset, nothin.
    Please anyone out there ? I'd be eternally grateful.

    If you cannot delete them on the Mac, it will probably be problematic trying to delete them on the iPad as well.
    You said you couldn't delete them on the Mac either. If you mean in the Mac mail app, don't delete them there. Delete them on the server in your web browser. Launch Safari - or whatever browser you use on the Mac and then go to your web mail and delete the email there.

Maybe you are looking for

  • Checkbox disable/ enable in tabular form

    Hi, I am using apex4.2, i have column "ACTIVE" in tabular form. it is simple check box type return value "Y/N". i want if i tick on one check box of active column then other check box should disable , and selected checkbox should have a value of "Y"

  • Remote access VPN with ASA 5510 using DHCP server

    Hi, Can someone please share your knowledge to help me find why I am not able to receive an IP address on remote access VPN connection while I can get an IP address on local DHCP pool? I am trying to setup remote access VPN with ASA 5510. It works wi

  • Adobe Digital Editions will not launch on my Windows 8.1 laptop

    Adobe Digital Editions will not launch on my Windows 8.1 laptop I have uninstalled and re-installed several times. I have successfully used previous versions of ADE on this laptop in the past.

  • Emails

    Hi champs, i am devloping a report in which i have to mail the report to the conser vendor, email id. can any one give me the code and steps for developing this report. <removed_by_moderator> <removed_by_moderator> vivek Edited by: Julius Bussche on

  • ICal and "To Do List"

    Thanks for taking the time to read my post! I just switched from a PC to an iMac last week so please bear wtih me if the answer to my question seems obvious. I run a small business and live and die by my calendar and customer database. I have success