Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Search file
Message
De
03/08/2004 10:46:49
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00930341
Message ID:
00930352
Vues:
11
Hi Vladimir,

Below is some code that gets all instances of a document type on a drive. You should be able to tweak it for your purposes, by modifying the ADIR parameters.

Alan
* Crawl through the directory tree

* Init
CLOSE DATABASES
SET SAFETY OFF
M.thispath=JUSTPATH(SYS(16))
SET DEFAULT TO &thispath

* Request the starting directory
lcRootDir = GETDIR()

=Crawl(lcRootDir, 'doc', 'doclist')
BROWSE NORM

*****************************************************************
*                                                               *
*                                                               *
*     Crawl down a directory tree and list the name and         *
*     directory of every file of one type in a cursor           *
*                                                               *
*     USAGE :  Crawl(cRootDirectory,cDocumentType,cCursorname)  *
*                                                               *
*                                                               *
*     Alan Shepard         30/11/2003                           *
*                                                               *
*     Checked on VFP7, VFP6                                     *
*                                                               *
*****************************************************************
FUNCTION Crawl
	PARAMETERS CurrDir, DocType, CursorName
	
	
	* Create cursor for the results if this is the first time the function
	* has been called
	IF TYPE('llFirstTime') = 'U'
		llFirstTime = .F.
		CREATE CURSOR &CursorName (filename C(20), dirname C(40))
		SELECT (CursorName)
	ENDIF
	
	* Create variables and make them private to this instance of the function
	LOCAL lnFileCount, lnDirCount, t
	LOCAL arrFileList(1,1), arrDirList(1,1)
	STORE 0  TO lnFileCount, lnDirCount, t
	STORE '' TO  arrFileList, arrDirList
	PRIVATE arrFileList, arrDirList, lnFileCount, lnDirCount, t
	
	* Get a list of files in current directory
	SET DEFAULT TO (CurrDir)
	lnFileCount = ADIR(arrFileList, '*.'+DocType)
	
	* Add file details to cursor
	FOR t = 1 TO lnFileCount
		APPEND BLANK
		REPLACE filename WITH arrFileList[t,1],;
		        dirname  WITH CurrDir
	ENDFOR
	
	* Get a list of subdirectories in current directory into array arrDirList
	lnDirCount = ADIR(arrDirList, '', 'D')
	
	* Deal with each subdirectory in turn
	FOR t = 1 TO lnDirCount
		IF arrDirList[t,1] <> '.'
			=Crawl(CurrDir+arrDirList[t,1]+'\', DocType, CursorName)
		ENDIF
	ENDFOR
	
ENDFUNC
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform