如何批量查找0字节的文件夹

总文件夹下有若干文件夹,想要批量查找出子目录下0字节的文件夹。Windows系统

在 要查找的 文件夹 ,打开命令行:
find . -name "*" -type f -size 0c

# 会列出tmp目录下文件大小为0字节的文件
find "/tmp" -size 0
# 要对文件进行处理的话,可以使用管道
find . -name "/tmp/" -size 0 -print0 | xargs -0 rm

查找当前目录下的空文件,注意是空文件不是空文件夹

find . -name "*" -type f -size 0c

查询当前目录下所有的空文件夹

find -type d -empty

查询所有/root/下的空文件夹,不会递归

find /root -type d -empty

删除所有空文件夹

find -type d -empty | xargs rm -rf

你想用什么语言


import os


def walkFile(file_path):
    # 遍历文件夹
    for root, dirs, files in os.walk(file_path):
        for f in files:
            path = os.path.join(root, f)
            if not os.path.getsize(path):
                print("空文件位置:", path)


if __name__ == '__main__':
    file_path = input('请输入文件夹路径:')
    walkFile(file_path)

还没说什么系统?

读取文件夹中的文件内容,判断文件大小是否为0。
用什么语言实现

linux上

查找空文件
 find . -name "*" -type f -size 0c 
查找空文件夹
find . -name "*" -type d -size 0c 

用powershell运行,改动一下startFolder

$startFolder = "C:\xxx"
$colItems = (Get-ChildItem $startFolder | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object)
foreach ($i in $colItems)
{
    $subFolderItems = (Get-ChildItem $i.FullName -recurse | Where-Object {$_.PSIsContainer -eq $False} | Measure-Object -property length -sum)
    if( ($subFolderItems.sum /1) -eq 0 )
    { 
        write-host $i.FullName -fore green
    } 
}

什么语言

搜索空文件夹软件
链接:https://pan.baidu.com/s/1nOdZncJMMu4ribycpTTkzA
提取码:saqt

可以试试 find "/tmp" -size 0
/tmp 要查找的路径