[if exist *] always exists

January 7, 2012 at 13:15:15
Specs: Windows 7
Hi. I'm trying to remove a directory if it's empty.
I know there are other solutions but I was wandering if there is a way to do with [if exist].

I tryied this: [if exist folder\* ( echo is empty )]
but it prints "is empty" although it's not empty

Maybe [folder\*] includes [.] and [..] "folders". If it so, how can I exclude them?

See More: [if exist *] always exists

Report •

January 8, 2012 at 14:09:36
Hi maestrokame,

If you are doing this in a batch file, you could do it by putting the output of a bare dir into a tmp file, setting a variable equal to the contents of the tmp file, and then checking to see if the variable is equal to null. I think it would be something like this:

@echo off
dir /b \folder > tmp.tmp
set /p var=<tmp.tmp
if [%var%]==[] echo is empty

Report •
Related Solutions

Ask Question