grub4dos icon indicating copy to clipboard operation
grub4dos copied to clipboard

Query: How to test for existence of an empty folder?

Open steve6375 opened this issue 5 years ago • 14 comments
trafficstars

image 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?

steve6375 avatar Jun 07 '20 11:06 steve6375

P.S. ls /ss works but ss could be a file.

steve6375 avatar Jun 07 '20 11:06 steve6375

ls /empty_folder/ > nul ;; echo %@retval%

ls /not_empty_folder/ > nul ;; echo %@retval%

yaya2007 avatar Jun 08 '20 00:06 yaya2007

empty1 does not exist empty and ss are empty folders

image

steve6375 avatar Jun 08 '20 08:06 steve6375

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 .

yaya2007 avatar Jun 08 '20 10:06 yaya2007

image

if exist works on NTFS volumes but not on FAT32 volumes.

steve6375 avatar Jun 08 '20 10:06 steve6375

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.

yaya2007 avatar Jun 09 '20 01:06 yaya2007

ls /empty_folder > nul ;; echo %@RetVal%

But empty_folder could be a file OR a folder. I want to test ONLY for a folder.

steve6375 avatar Jun 09 '20 08:06 steve6375

ls /empty_folder > nul ;; echo %@RetVal%这是测试有没有这个文件/文件夹

ls /empty_folder/ > nul ;; echo %@RetVal%这是测试文件夹内有没有文件

yaya2007 avatar Jun 09 '20 09:06 yaya2007

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.

steve6375 avatar Jun 09 '20 09:06 steve6375

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.

steve6375 avatar Jun 09 '20 09:06 steve6375

image

steve6375 avatar Jun 09 '20 09:06 steve6375

ls /empty will work for /empty1 and /empty2 also

ls /empty/ will not work for /empty1 and /empty2 also

yaya2007 avatar Jun 09 '20 11:06 yaya2007

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?

steve6375 avatar Jun 09 '20 13:06 steve6375

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

deomsh avatar Jul 14 '20 22:07 deomsh