Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I shut down echo for this "for" cycle inputed from cmd?

Tags:

windows

cmd

I was trying to use this excellent answer.

Is there a way to have ONE command line that executes the following (delete all files of size zero) without printing any output?

for /r %F in (*) do if %~zF==0 del "%F"

(It shows all the expanded commands, also when the size is not zero)

I have tried to use How to redirect stderr to null in cmd.exe, (trying >, 1> and 2>) with no avail...

like image 488
Antonio Avatar asked Dec 21 '22 02:12

Antonio


2 Answers

@ suppresses the output for one command. So the following does what you want:

for /r %F in (*) do @if %~zF==0 @del "%F"

To show (only) the files that were deleted:

for /r %F in (*) do @if %~zF==0 del "%F" & echo removed %F
like image 169
Chowlett Avatar answered Feb 12 '23 18:02

Chowlett


@echo off && for /r %F in (*) do if %~zF==0 del "%F" > NUL

The > NUL is because I can't recall if certain situations cause del to try to output

like image 30
MDEV Avatar answered Feb 12 '23 16:02

MDEV