Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I check if a directory is empty?

Status
Not open for further replies.

BlackTL

Technical User
Aug 11, 2003
29
US
I would like to check if a directory is empty and I can not get it to work. What I am doing is storing the path in a string e.g. "D:\Somedirectory\*.*" and using the dir function in Access to check if it exists. When I search for the directory, it returns "." which means there is something in that directory when there actually isn't. If I search for a specific file such as "d:\somedirectory\*.xls", it returns null which is true. Is using the "*.*" a wrong method of checking whether or not a directory exists?

Your help is appreciated!

Thanks
Rosh
 
Oops! I posted in the wrong forum. Could someone transfer this thread to the VBA/Modules forum?

Thanks!
 
Actually, all directories have two files in them ".", and "..", but you can't see them as they are hidden.

"." refers to the current directory
".." referes to the parent directory

You are on the right track in using the Dir function, you just need to account for the "." and ".." directories, knowing they will always be there. An empty directory would be one that only contains those two entries, and nothing else.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top