Java File Path Delete deleteEmptDir(String Path, String username)

Here you can find the source of deleteEmptDir(String Path, String username)

Description

This Method is responsible for deleting the author dir in which permission given when it empty

License

Open Source License

Parameter

Parameter Description
Path String
username String

Declaration

public static void deleteEmptDir(String Path, String username) 

Method Source Code


//package com.java2s;
import java.io.File;
import java.util.Vector;

public class Main {
    /**//from   www  .  j a v a  2s .  c o  m
    * This Method is responsible for deleting the author dir
    * in which permission given when it empty
    * @param Path String
    * @param username String
    */
    public static void deleteEmptDir(String Path, String username) {
        String pathdir = Path + "/" + username;
        File fdir = new File(pathdir);
        Vector y = new Vector();
        String ContentList[] = fdir.list();
        for (int j = 0; j < ContentList.length; j++) {
            y.add(ContentList[j]);
        }
        if (y.size() == 0)
            deleteFile(fdir);
    }

    /**
    * This Method is responsible for deleting the file and dir 
    * @param f File
    */
    public static void deleteFile(File f) {
        int i = 0;
        if (f.isDirectory()) {
            File file[] = f.listFiles();
            while (i < file.length) {
                deleteFile(file[i]);
                i++;
            }
        }
        f.delete();
    }
}

Related

  1. deleteDirRecursive(String dirPath)
  2. deleteDirRecursive(String path)
  3. deleteDirs(File path)
  4. deleteDirs(String pathname)
  5. deleteDirWithContent(final String path)
  6. deleteEmptyDir(File dstPath)
  7. deleteEmptyParents(final File path)
  8. deleteFile(File path)
  9. deleteFile(File path)