Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Rick C. Hodgin
  Where is Rick C. Hodgin?
 Indianapolis
 Indiana - United States
 Rick C. Hodgin
 To: Koen Piller
  Where is Koen Piller?
 Santpoort-Zuid
 Netherlands
 Koen Piller
 Tags
Subject: RE: remove directory
Thread ID: 373496 Message ID: 373500 # Views: 71 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Classes and Objects
Date: Friday, March 22, 2013 4:14:18 PM         
   


> Hi,
>
> do we have a syntax to remove a directory and all its subs, even if there is data in any? For OS WIN7
>
> Regards,
>
> Koen
>
>
> ** The coding in VFP without using mDot should be qualified as recreational **


I rolled my own for a backup-to-floppy-drive project. You can remove the DRIVETYPE() test.

*** NOTE: I warn you that it does work and it is quite unforgiving. Use sparingly. You could add the RECYCLE keyword on if you'd like.

**********
* Method:
*     mth_wipe_directory
**********
* Note:  If we are to wipe subdirs, then after every file in the
*        specified tcWipeDir is deleted, including all subdirs, then
*        the tcWipeDir directory itself is deleted.
*****
* Note:  The tnErrors clause needs to be passed by reference (@tnErrors)
*****
LPARAMETERS tcWipeDir, tlWipeSubdirs, tnErrors
LOCAL lnI, lcSaveDir, laFiles


* Make sure we have something to do and that we're ONLY doing it to a floppy drive
IF DRIVETYPE(JUSTDRIVE(FULLPATH(tcWipeDir))) = 2 AND DIRECTORY(tcWipeDir)
	TRY
		* Save where we are
		lcSaveDir = FULLPATH(CURDIR())
		CD (tcWipeDir)
		
		* Get a list of all files
		DIMENSION laFiles[1]
		ADIR(laFiles, "*.*", "SHD")
		FOR lnI = 1 TO ALEN(laFiles, 1)
			IF NOT INLIST(laFiles[lnI,1], ".", "..")
				IF "D" $ laFiles[lnI, 5]
					* It's a directory
					IF tlWipeSubdirs
						this.mth_wipe_directory(ADDBS(tcWipeDir) + laFiles[lnI, 1], tlWipeSubdirs, @tnErrors)
					ENDIF
				ELSE
					* It's a file, delete it
					ERASE (laFiles[lnI, 1])
				ENDIF
			ENDIF
		NEXT
		
		* Get back to where we once belonged
		CD (lcSaveDir)
		
		* When we get here, everything's been wiped
		* If we're not in the root directory, attempt to delete it
		IF tlWipeSubdirs AND RIGHT(ADDBS(FULLPATH(tcWipeDir)), 2) != ":\"
			* Remove this directory
			TRY
				RD (tcWipeDir)
			CATCH
				tnErrors = tnErrors + 1
			ENDTRY
		ENDIF
	CATCH
		tnErrors = tnErrors + 1
	ENDTRY
ENDIF



Best regards,
Rick C. Hodgin

ENTIRE THREAD

remove directory Posted by Koen Piller @ 3/22/2013 3:47:27 PM
RE: remove directory Posted by Rick Hodgin @ 3/22/2013 4:14:18 PM
RE: remove directory Posted by Paul Gibson @ 3/22/2013 4:16:25 PM
RE: remove directory Posted by Samir H. @ 3/24/2013 8:28:18 AM
RE: remove directory Posted by Koen Piller @ 3/24/2013 1:40:08 PM
RE: remove directory Posted by Samir H. @ 3/24/2013 3:04:26 PM
RE: remove directory Posted by Koen Piller @ 3/24/2013 5:07:28 PM
RE: remove directory Posted by Rick Hodgin @ 3/24/2013 7:13:54 PM
RE: remove directory Posted by Koen Piller @ 3/24/2013 9:15:33 PM
RE: remove directory Posted by Rick Hodgin @ 3/24/2013 9:46:27 PM
RE: remove directory Posted by Koen Piller @ 3/24/2013 10:32:17 PM
RE: remove directory Posted by Rick Hodgin @ 3/24/2013 10:35:50 PM
RE: remove directory Posted by Rick Hodgin @ 3/24/2013 10:43:07 PM
RE: remove directory Posted by Koen Piller @ 3/24/2013 10:50:04 PM
RE: remove directory Posted by Rick Hodgin @ 3/24/2013 10:54:13 PM