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

VFP 7.0 how to tell if directory is empty 3

Status
Not open for further replies.

bettyfurr

Technical User
Mar 12, 2002
371
US
I want to delete a directory if there are no files are folders in the directory. What command can I tell it is empty?

Also, I will need to delete the directories and files if it is not empty.

Thanks!
 
IF ADIR(gaFiles, 'c:\test\*.*')>0
WAIT WINDOW "Files exist!"
ELSE
WAIT WINDOW "No Files found."
ENDIF
 
How do i know if they are folders/directories or they are files? I need to remove directories and erase files.

Please explain.

thanks.
 
If you have a squint at :

thread184-500831

I think you'll find the answer!

HTH

Regards

Griff
Keep [Smile]ing
 
*Example directory structure delete
*Created a directory c:\tracy for testing purposes
*C:\tracy has 2 subfolders and each subfolder has
*2 files for testing purposes
SET SAFETY OFF
IF FILE('dirlist.dbf')
DELETE FILE ('dirlist.dbf')
ENDIF
* Pass the name of the directory you wish to delete
*all of its files and subdirectories
DO getdirs WITH "C:\tracy"
IF USED('dirlist')
SELE dirlist
GO TOP
SCAN
IF ADIR(gaFiles, dirlist.dirname+'*.*')>0
FOR i = 1 TO ALEN(gaFiles,1)
IF FILE(dirlist.dirname+gaFiles(i,1))
DELE FILE (dirlist.dirname+gaFiles(i,1))
ENDIF
ENDFOR
ENDIF
ENDSCAN
FOR i = RECCOUNT() TO 1 STEP -1
GOTO i
IF DIRECTORY(dirlist.dirname)
lcommand="RMDIR "+dirlist.dirname
&lcommand
ENDIF
ENDFOR
ENDIF
IF USED('dirlist')
USE IN dirlist
ENDIF
RETURN


PROCEDURE getdirs
LPARAMETERS tcPath
IF UPPER(TYPE('tcpath'))="L"
tcPath="c:\"
ENDIF
CREATE CURSOR dirlist (dirname m)
GetSubDirs(tcPath)
RETURN


FUNCTION GetSubDirs
LPARAMETERS tcPath
LOCAL lcCurDir, lnSubDirs, ix
LOCAL ARRAY laDirs[1]
lcCurDir = ADDBS(tcPath)
INSERT INTO dirlist VALUES (lcCurDir)
lnSubDirs=ADIR(laDirs,lcCurDir+"*.*","D")
FOR ix = 1 TO lnSubDirs
IF laDirs[ix,1]#"." AND "D"$laDirs[ix,5]
=GetSubDirs(lcCurDir+laDirs[ix,1])
ENDIF
ENDFOR
RETURN
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top