递归删除0KB文件使用Windows cmd [英] Recursively delete 0KB files using windows cmd
问题描述
我有一些进程在目录及其子目录中创建一些大小为0KB的文件。
如何使用Windows命令提示符从文件系统中删除文件?
任何单个命令或脚本将执行任务将工作。
我只能运行简单的cmd命令和脚本,在受限访问的远程机器上工作。
-
对文件递归迭代:
F in(*)
-
找出零长度文件:
如果%〜zF == 0
-
删除它们:
del%F
整合在一起:
for / r%F in(*)do if%〜zF == 0 del%F
如果在批处理文件中需要这样,那么需要将%
:
for / r %% F in(*)do if %%〜zF == 0 del%% F
注意:我假设您的意思是文件长度为0字节。如果0 KB意味着小于1000字节,则
如果需要读取
如果%〜zF LSS 1000
或任何您的阈值。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"
Putting it all together:
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"
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 readif %~zF LSS 1000
or whatever your threshold is.这篇关于递归删除0KB文件使用Windows cmd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!