+ Reply to Thread
Results 1 to 2 of 2

Thread: delete file or directory

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    15

    delete file or directory

    I have a folder that contains files inside it , i was wondering how can i delete each file in that directory ?
    Also i`d like to know how can i delete a specific file if it is exist.

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    24
    To delete directory loop through each file and delete it , for example :
    Code:
    if (dir.isDirectory()) {
            String[] children = dir.list();
            for (int i = 0; i < children.length; i++) {
                new File(dir, children[i]).delete();
            }
        }
    Delete a specific file :
    Code:
    File file = new File(FILEPATH);
    if(file.exists()) file.delete();

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts