grub4dos
grub4dos copied to clipboard
Query: How to test for existence of an empty folder?
hd0,0 is NTFS
hd0,1 is FAT32
(hd0,1)/ss is empty folder (hd0,0)/empty is empty folder
if exist works on NTFS empty folders but does not work if FAT32 partition. How can I test if a folder exists (empty or not empty) on any type of partition?
P.S. ls /ss works but ss could be a file.
ls /empty_folder/ > nul ;; echo %@retval%
ls /not_empty_folder/ > nul ;; echo %@retval%
empty1 does not exist empty and ss are empty folders

empty1 does not exist return 0 empty and ss are empty folders return 0 e2b are not empty folders return 1
The key is to judge whether empty1 exists .

if exist works on NTFS volumes but not on FAT32 volumes.
ls /empty_folder/ > nul ;; echo %@RetVal% 0
ls /not_empty_folder/ > nul ;; echo %@RetVal% 1 //============================================= ls /empty_folder > nul ;; echo %@RetVal% 1
ls /non_existent_folder > nul ;; echo %@RetVal% 0 //============================================= It can distinguish between empty and non empty folders. It can be distinguished that the folder exists / does not exist.
ls /empty_folder > nul ;; echo %@RetVal%
But empty_folder could be a file OR a folder. I want to test ONLY for a folder.
ls /empty_folder > nul ;; echo %@RetVal%这是测试有没有这个文件/文件夹
ls /empty_folder/ > nul ;; echo %@RetVal%这是测试文件夹内有没有文件
ls /empty_folder/> nul ;; echo% @RetVal %This is the test folder for files But the folder is empty! I want to test for a folder that is empty.
ls /empty_folder/ > nul ;; echo %@retval% ls /nonexist_folder/ > nul ;; echo %@retval%
ls /empty will work for /empty1 and /empty2 also
The main problem is if exist works on NTFS volumes but not on FAT32 volumes.

ls /empty will work for /empty1 and /empty2 also
ls /empty/ will not work for /empty1 and /empty2 also
Can you suggest code for testing that \empty is a folder and it contains no files and that no other folders beginning with empty exists?
Maybe using stdout can be helpfull?
debug 1 ;; set size= ls /fileodir/ > null || cat --length=0 /fileodir | set size= && if not exist size && echo fileodir is an EMPTY FOLDER
On FAT32 a folder gives no stdout with cat --length=0 (different on NTFS!).
Sorry, can´t upload my printscreen somehow.
Another possibilty is using FAT:
fat dir /fileodir > null && ls /fileodir/ > null || echo fileodir is a directory and this directory is empty