zoukankan      html  css  js  c++  java
  • 实用代码:清理空文件夹

     Java代码(需要安装java环境)

    import java.io.File;
    import java.io.IOException;

    /**
    * @author 王大仙儿
    * @date 2019/12/16 16:47
    */
    public class CleanNullFile {

    public static void main(String[] args) {
    if (args[0].isEmpty()) {
    System.out.println("请输入路径");
    } else {
    for (String path : args) {
    File file = null;
    try {
    file = new File(path + File.separator + "正在删除空文件夹");
    if(file.createNewFile()){
    clean(path);
    }else{
    System.err.println("操作文件夹失败,请检查目录权限");
    }
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    if (file != null) {
    file.delete();
    }
    }
    }
    }
    }

    private static void clean(String path) {
    File[] files = new File(path).listFiles();
    if (files.length == 0) {
    File file = new File(path);
    if (file.delete()) {
    System.out.println("删除空文件夹:" + file.getPath());
    } else {
    System.err.println("删除文件夹失败:" + file.getPath());
    }
    clean(file.getParent());
    } else {
    for (File file : files) {
    if (file.isDirectory()) {
    clean(file.getPath());
    }
    }
    }
    }

    }
  • 相关阅读:
    单页面应用(SPA)如何实现---流程细解
    Java基础之面向对象
    Java的基础知识
    java是什么?初始java
    AuthenticationManager的认证流程
    核心组件之UserDetailService的详解
    Auth模块
    python基础
    算法与数据结构学习目录
    Django----------视图层
  • 原文地址:https://www.cnblogs.com/wangdaxianer/p/12050638.html
Copyright © 2011-2022 走看看