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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

determining if a directory contains files 4

Status
Not open for further replies.

chiefman

Programmer
Oct 17, 2003
94
US
I was wondering if anyone knew a good way to determine if a directory contained files (or it would also work if there was an easy way to determine if the directory was empty)? I have a search set up in my code that goes through all the subfolders in a certain network drive looking for a particuler subfolder under each job number, but once I get to that point I can't figure out how to look in the directory to see if it has files in it or if it is empty. Any suggestions would be greatly appreciated. Thanks.
 
Look up the Dir function in VB Help. You can use wildcards to look for files. You may need to set Microsoft Scripting Runtime in your program reference befor this will work.

Carl W
 
This works.....

Private Declare Function PathIsDirectoryEmpty Lib "shlwapi" _
Alias "PathIsDirectoryEmptyA" _
(ByVal pszPath As String) As Long

Public Function IsDirEmpty(ByVal strPath As String) As Boolean

'Sample usage: MsgBox IsDirEmpty("D:\WUTemp\")
IsDirEmpty = PathIsDirectoryEmpty(strPath) = 1

End Function

 
Or this ....

Dim MyDir As String
MyDir = Dir("d:\wutemp\*.*")
If MyDir = "" Then MyDir = "Empty"
MsgBox MyDir
 
Thanks, ccwj and bmdb. That info was just what I was looking for. Thanks again!
 
Have another star folks, I'll need that soon. Thanks
 
ccwj, you don't need Scripting runtime to use the Dir function

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
I'll say it again.

STAY THE HELL AWAY FROM DIR()!!!

It only allows one search at a time - there are alternatives.


mmilan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top