Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Determine if folder have a file or not in batch

Simple thing I want to do but,
I try to do this with no success

@echo off

:start
if not exist "input" mkdir input

if not exist input\* echo Please put a video in "input" folder. && pause && goto start 

echo there is a file in "input" folder.
pause

Any help to fix?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

try to list files and see if it finds some:

dir /b /a-d input\* >nul 2>&1 && echo there is a file || echo folder is empty

/a-d excludes subfolders (lists files only)
>nul 2>&1 discards the output of dir (we don’t need it, just if it is successful or not)
&& acts as if previous command was successful (files were found) then,
|| means if it failed (no files found) then

(just to explain why if exist doesn’t work: it finds . and .. (current folder and parent folder), which technically are files)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading