使用windows cmd递归删除0KB文件 [英] Recursively delete 0KB files using windows cmd
问题描述
我有一些进程可以在目录及其子目录中创建一些 0KB 大小的文件.
如何使用 Windows 命令提示符从文件系统中删除文件?
将执行该任务的任何单个命令或脚本都将起作用.
我只能运行简单的 cmd 命令和脚本,在访问受限的远程机器上工作.
I have some process which creates some files of 0KB size in a directory and its sub-directories.
How can I delete the files from the file system using the windows command prompt?
Any single command or a script that will do the task will work.
I can only run simple cmd commands and scripts, working on a remote machine with restricted access.
推荐答案
递归遍历文件:
Iterate recursively over the files:
for /r %F in (*)
找出零长度文件:
Find out zero-length files:
if %~zF==0
删除它们:
Delete them:
del "%F"
综合起来:
for /r %F in (*) do if %~zF==0 del "%F"
如果你在批处理文件中需要这个,那么你需要将%
加倍:
If you need this in a batch file, then you need to double the %
:
for /r %%F in (*) do if %%~zF==0 del "%%F"
注意:我假设您的意思是长度恰好为 0 字节的文件.如果 0 KB 意味着小于 1000 字节,那么上面的 if
需要读取 if %~zF LSS 1000
或任何您的阈值.
Note: I was assuming that you meant files of exactly 0 Bytes in length. If with 0 KB you mean anything less than 1000 bytes, then above if
needs to read if %~zF LSS 1000
or whatever your threshold is.
这篇关于使用windows cmd递归删除0KB文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!