IsDirEmpty

Just starting out? Need help? Post your questions and find answers here.
AZJIO
Addict
Addict
Posts: 1372
Joined: Sun May 14, 2017 1:48 am

IsDirEmpty

Post by AZJIO »

Code: Select all

; Is it safe to do this:
Procedure IsDirEmpty1(Path$)
	Protected i = 0
	If ExamineDirectory(0, Path$, "*")
		While NextDirectoryEntry(0)
			i+1
			If i > 2
				i = 0
				Break
			EndIf
		Wend
		FinishDirectory(0)
	Else
		i = -1
	EndIf
	ProcedureReturn i
EndProcedure


Procedure IsDirEmpty(Path$)
	Protected res$, i = 1
	If ExamineDirectory(0, Path$, "*")
		While NextDirectoryEntry(0)
			res$ = DirectoryEntryName(0)
			If res$ = ".." Or res$ = "."
				res$ = ""
				Continue
			EndIf
			If res$
				i = 0
				Break
			EndIf
		Wend
		FinishDirectory(0)
	Else
		i = -1
	EndIf
	ProcedureReturn i
EndProcedure

Debug IsDirEmpty(GetHomeDirectory() + "test1")
Found old examples. But that was after I wrote my examples
BarryG
Addict
Addict
Posts: 3330
Joined: Thu Apr 18, 2019 8:17 am

Re: IsDirEmpty

Post by BarryG »

For Windows only:

Code: Select all

Debug PathIsDirectoryEmpty_(dir$)
Post Reply