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

Function to return whether Folder/Directory is Empty

Usefull Functions & Procedures

Function to return whether Folder/Directory is Empty

by  GriffMG  Posted    (Edited  )
Someone asked this question today, so I thought I'd make it a FAQ so everyone can benefit from it.

Code:
** usage ? EmptyDir("c:\apps\myfolder\*.*")
**   or  ? EmptyDir("c:\apps\myfolder\")
**   or  ? EmptyDir("c:\apps\myfolder")
** returns .t. if empty, .f. if not empty

Function EmptyDir
  parameter m.Path
  local m.flg,m.count,i
  **
  ** test the end of the folder name and put wildcards on
  **
  if Right(m.path,4) <> "\*.*"
     if Right(m.path,1) <> "\"
       m.Path = m.Path+"\*.*"
     else
       m.Path = m.Path+"*.*"
     endif
  endif
  m.flg = .f.
  m.count = Adir(TmpArray,m.Path,"DHS")
  if m.count = 0
     m.flg = .t.
  else
    ** check for the entries for folders . and ..
    m.flg = .t.
    for i = 1 to m.count
      if !(TmpArray[i,1] == "." .or. TmpArray[i,1] == "..")
         m.flg = .f.
         i = m.count
      endif
    next
  endif
return(m.flg)
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top