Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Coding Question
Message
De
15/02/2010 07:55:25
 
 
À
15/02/2010 07:30:02
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Versions des environnements
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Network:
Windows XP
Divers
Thread ID:
01449158
Message ID:
01449163
Vues:
72
Hi Rich,

>Within FoxPro, do we have a way to:
>1) Delete an entire folder on one drive and then...
>2) Copy an entire folder from one drive to another drive?
>
>Can surely use the help.
>Rich Murillo

I posted this code some time ago in my blog, but as it is written in german, I just changed the comments and place it here.
* Functiontest
LOCAL v1 as String, v2 as String, rv as Boolean
* Copy Test
v1 = [define your sourcepath here or just call GETFILE()]
v2 = [c:\temp\copied\]
rv = CopyFolder(v1,v2)
MESSAGEBOX([COPY Function ] + TRANSFORM(rv),0+64+0,[Info])
* Move Test
v1 = [c:\temp\copied\]
v2 = [c:\temp\moved\]
rv = MoveFolder(v1,v2)
MESSAGEBOX([MOVE Function ] + TRANSFORM(rv),0+64+0,[Info])
* Delete Test
v1 = [c:\temp\moved\]
rv = DeleteFolder(v1)
MESSAGEBOX([DELETE Function ] + TRANSFORM(rv),0+64+0,[Info])
RELEASE v1, v2, rv

FUNCTION CopyFolder as Boolean 
LPARAMETERS vSrcDir as String, vTgtDir as String
	LOCAL oFSO as Object, llOverwrite as Boolean, llReturn as Boolean
	llReturn = .F.
	* // Check Source-directory
	IF DIRECTORY(m.vSrcDir)
		* // Check if Target-drive exists 					
		IF DIRECTORY(JUSTDRIVE(m.vTgtDir))
			m.vSrcDir	= JUSTPATH(ADDBS(m.vSrcDir))
			m.vTgtDir	= JUSTPATH(ADDBS(m.vTgtDir))
			llOverWrite	= .T.
			oFSO		= CREATEOBJECT([Scripting.FileSystemObject])
			oFSO.CopyFolder(m.vSrcDir, m.vTgtDir, llOverwrite) 
		ENDIF 
	ENDIF 
	oFSO = []
	RELEASE oFSO
	IF DIRECTORY(m.vTgtDir)
		llReturn = .T.
	ENDIF 
	RETURN llReturn
ENDFUNC 

FUNCTION MoveFolder as Boolean 
LPARAMETERS vSrcDir as String, vTgtDir as String
	LOCAL oFSO as Object, llReturn as Boolean
	llReturn = .F.
	* // Check if Source-Directory exists
	IF DIRECTORY(m.vSrcDir)
		* // Check if Target-Drive exists
		IF DIRECTORY(JUSTDRIVE(m.vTgtDir)) ;
		AND !DIRECTORY(m.vTgtDir)
			m.vSrcDir	= JUSTPATH(ADDBS(m.vSrcDir))
			m.vTgtDir	= JUSTPATH(ADDBS(m.vTgtDir))
			oFSO		= CREATEOBJECT([Scripting.FileSystemObject])
			oFSO.MoveFolder(m.vSrcDir, m.vTgtDir) 
			IF DIRECTORY(m.vTgtDir)
				llReturn = .T.
			ENDIF 
		ENDIF 
	ENDIF 
	oFSO = []
	RELEASE oFSO
	RETURN llReturn
ENDFUNC 

FUNCTION DeleteFolder as Boolean 
LPARAMETERS vTgtDir as String
	LOCAL oFSO as Object, llReturn as Boolean, llForceDel as Boolean
	llReturn = .T.
	* // Check if directory exists
	IF DIRECTORY(m.vTgtDir)
		m.vTgtDir	= JUSTPATH(ADDBS(m.vTgtDir))
		llForceDel	= .T. 
		oFSO		= CREATEOBJECT([Scripting.FileSystemObject])
		oFSO.DeleteFolder(m.vTgtDir, llForceDel) 
	ENDIF 
	oFSO = []
	RELEASE oFSO
	IF DIRECTORY(m.vTgtDir)
		llReturn = .F.
	ENDIF 
	RETURN llReturn
ENDFUNC 
Best Regards
-Tom

Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it.

Oh, and BTW: 010101100100011001010000011110000101001001101111011000110110101101110011
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform