#1. The 1st example below from SS64 gives not empty when there are no files in the folder but there is an empty subfolder.
#2. The 2nd example reports empty even when there is a file in a sub-folder, not in root.
What I wish to get is report as not empty when there is say a file in a sub-folder but none in root folder.
When I saw the issue (for my needs) RE: #1. of reporting not empty even with no files, I thought of using #2. to supplament #1. with #2.
However #2. reports empty when there is a file in a subfolder.
This sums up what I want to achieve .. determine if folder is empty of files, whether they are anywhere within the main root folder or subfolder.
I haven't yet found a solution, appreciate any help with this. I've tried this page also, same result as SS64.
https://stackoverflow.com/questions/17744981/check-folder-is-empty-using-batch-command
1st. test layout, 1 subfolder, no files. Wish to get a result/answer of NO files. ...
Example layout D:\TEST\TEST2\ in this example the 1st. of two examples below will report folder "TEST" as not empty.
That's expected because there is no -d.
I had hoped that the 2nd example would work for my requirements but if I put a file into a subfolder, none in the root then it reports as no files present.
There are the 2 examples in SS64 CMD. I did a copy and paste here.
How To: Find out if a directory is empty ...
https://ss64.com/nt/syntax-empty.html
@Echo off
Setlocal
Set _folder="C:\Demo"
For /F %%A in ('dir /b /a %_folder%') Do (
Echo The folder is NOT empty
gotok
)
Echo The folder is empty
k
The script above will scan all files in the folder, which may be slow if there are many thousands of files, but it does not recursively scan through all the subdirectories, if a single subdirectory is found, empty or not, that is read as the parent directory is not empty.
To ignore sub-directories and only report an absence of files, use the alternative below, this excludes directories even if they have a period in the directory name:
@Echo off
Setlocal
Set _folder="C:\Demo"
dir /A/B %_folder% >NUL 2>&1 && (
ECHO Source Folder is NOT empty.
gotok
)
Echo The folder is empty
k
+ Reply to Thread
Results 1 to 2 of 2
-
-
I may have hit gold. I had spent a long time time looking but kept at it after my initial post. A lot of the time it depends on how you word the search.
Anyway, sorry for mess.
REM https://stackoverflow.com/questions/10813943/check-if-any-type-of-files-exist-in-a-dir...g-batch-script
>nul 2>nul dir /a-d /s "#01-Source\*" && (echo Files exist) || (echo No file found)
Similar Threads
-
help needed compress a dvd folder audio.ts &video.ts folder to 8gb files
By barry25 in forum Authoring (DVD)Replies: 4Last Post: 13th Jul 2024, 14:25 -
delete files in a folder
By marcorocchini in forum Newbie / General discussionsReplies: 7Last Post: 9th Feb 2023, 19:57 -
Using handbvrake to remove subtitles from a folder of files
By RBCC in forum SubtitleReplies: 1Last Post: 22nd Mar 2022, 06:48 -
Batch-Delete Audio Track 2 of MP4s of a directory incl. subfolders!
By piknockyou in forum AudioReplies: 0Last Post: 23rd May 2021, 12:26 -
How to add cover to files in folder?
By bradwiggo in forum Newbie / General discussionsReplies: 8Last Post: 21st May 2021, 08:42