S
S
Slavka2013-12-15 16:28:45
cmd/bat
Slavka, 2013-12-15 16:28:45

Batch file that defines a directory to be empty?

help, how to check the directory for emptyness using the bat command file, like if it is empty, display "yes" if it is not empty, display "no"
I tried everything, I don't know how to do it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Skobelkin, 2013-12-15
@Slavka_online

@echo off

set dir=C:\aaa

set result=folder is empty
if exist "%dir%" for /f "usebackq" %%f in (`dir "%dir%\" /b /a:`) do set result=folder is not empty

echo %result%

This code sets the result variable to "folder is empty". After that, using for iterates through each file in the folder and sets the value of the result variable to "folder is not empty" in this loop. Accordingly, if the folder is empty, then the command to set the value of the variable will not be executed even once and the value in it will remain the original.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question