---
title: "删除一个文件夹中的空文件夹"
author: "ttf177"
date: "2010-07-22T17:50:20Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2010-07-22T17:55:12Z"
id: 719140
url: "https://ttf177.iteye.com/blog/719140"
---

```
/**
	 * 删除指定目录下的空文件夹。
	 * 
	 * @param path
	 *            文件夹路径。
	 */
	public static void clearEmptyFolder(String path) {
		File file = new File(path);
		if (!file.exists()) {
			return;
		}
		if (!file.isDirectory()) {
			return;
		}

		File[] files = file.listFiles();
		if (files != null && files.length <= 0) {
			file.delete();
			return;
		}
		for (File f : files) {
			if (f.isDirectory()) {
				clearEmptyFolder(f.getPath());
				f.delete();
			}
		}
	}
```