VideoHelp Forum




+ Reply to Thread
Results 1 to 2 of 2
  1. Member
    Join Date
    Jun 2022
    Location
    Dublin
    Search Comp PM
    #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
    goto k
    )
    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.
    goto k
    )
    Echo The folder is empty
    k
    Quote Quote  
  2. Member
    Join Date
    Jun 2022
    Location
    Dublin
    Search Comp PM
    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)
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!