batch-file - 使用批处理在目录下查找大小为 0 的特定文件夹
问题描述
有人可以帮助如何使用批处理在目录下查找大小为 0 的特定文件夹吗?谢谢你。
父文件夹中有很多文件夹,其中一些文件夹里面有文件,一些文件夹是空的。我想使用批处理文件找出空文件夹的名称。有人可以帮忙吗?谢谢
解决方案
此脚本扫描目标文件夹并返回目标文件夹中所有空子文件夹的 UNC 路径。
@echo off
setlocal EnableDelayedExpansion
REM This script scans the target folder and returns the UNC paths of all empty subfolders within the target folder.
title Looking for empties, please wait!
cd "%~dp0"
cls
if "%~1" == "" (
echo ERROR: No folder was specified! You gotta tell me where to look for empties!
echo Please drag-and-drop a folder onto the icon for this script.
pause
exit /b
)
if not exist "%~dpn1" (
echo ERROR: The folder you told me to scan doesn't seem to exist!
pause
exit /b
)
set "target=%~dpn1"
echo Scanning: %target%
echo.
REM Grab each subfolder for checking.
for /f "tokens=*" %%a in ('dir "%~dpn1" /s /b /a:d') do (call :checkForBlanks "%%a")
echo.
echo Done.
title Done.
pause
exit /b
:checkForBlanks
REM We've been given a folder. We must check if it's empty.
set "folder=%~1"
set "scanned=!folder:%target%=!"
title Looking for empties: %scanned:&=^&%
set exist=
for /f %%a in ('dir "%~1" /b') do (set "exist=%%a" & goto :found)
:found
if "%exist%" == "" echo EMPTY: %scanned:&=^&%
goto :eof
推荐阅读
- spring - 将“DefaultCookieSerializer”注释为“@Component”时,将“SameSite”cookie 值设置为“none”不起作用
- google-chrome-extension - 如何通过在扩展程序中触发 url 使用客户端 ID 从谷歌获取访问令牌
- kubernetes - Google Kubernetes Engine 防火墙规则上的 nginx 入口控制器
- amazon-web-services - 是否可以在 AWS 中标记 SSH 密钥对?
- feature-engineering - trans_primitives 和 agg_primitives 中使用的选项列表
- .net-core - .NET Core 应用程序中的 Sonarqube 规则 S4823“使用命令行参数是安全敏感的”
- python - 在python中多处理大量数据
- pandas - 循环遍历数据框字典并计算一列
- java - 如何在 Intellij 中为 catch 语句更改速度模板
- c# - 是否可以将运算符存储在变量中