Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adir() help
Message
From
03/06/2008 16:52:44
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00909947
Message ID:
01321438
Views:
31
>Hi Gary,
>
>Here's my _CDIR function that creates a cursor instead of array and can search subdirectories.
? _CDIR("crsDirs", "h:\temp", "*.PDF", "SUBDIR BASIC")
>...
>* FUNCTION _CDIR
>* Param's....: 1 - Cursor Name (R)
>* 	 : 2 - Directory
>* 	 : 3 - File search skeleton.
>* 	 :     Multiple skeletons can be sepaarted by ';' (semicolon) or ',' (comma)
>* 	 :     Can also be 1-d array with file skeletons
>* 	 : 4 - Options: SUBDIR - recursively scan all subdirectories
>* 	 :				BASIC - creates cursor w/o aditional fields
>* 	 :
>* 	 : 5 - File attributes. Passed to ADIR as cAttribute parameter
>* 	 : 6 - Flags. Passed to ADIR as nFlag parameter
>*
>LPARAMETERS tcCursorName, tcPath, tvPattern, tcOpt, tcAttributes, tnFlag
>LOCAL lcCursorName, laPattern[1], lcAttributes, lnFlag, lcPath, laPattern, ;
>       lcOpt, llRecursive, i, llBasicData
>
>EXTERNAL ARRAY tvPattern
>
>lcCursorName = UPPER(ALLTRIM(tcCursorName))
>lcPath =ADDBS(UPPER(ALLTRIM(tcPath)))
>
>DO CASE
>CASE TYPE([ALEN(tvPattern)]) = "N"
>	= ACOPY(tvPattern, laPattern)
>CASE ";" $ tvPattern
>	= ALINES(laPattern, UPPER(tvPattern), .T., ";")
>CASE "," $ tvPattern
>	= ALINES(laPattern, UPPER(tvPattern), .T., ",")
>OTHERWISE
>	laPattern[1] = UPPER(tvPattern)
>ENDCASE
>
>FOR i=1 TO ALEN(laPattern)
>	laPattern[i] = UPPER(laPattern[i])
>ENDFOR
>
>lcAttributes = IIF( Empty( tcAttributes) Or VarType(tcAttributes) <> "C", "", ;
>	UPPER(ALLTRIM(tcAttributes)))
>
>lnFlag = IIF( Empty( tnFlag) Or VarType(tnFlag) <> "N", 0, tnFlag)
>
>lcOpt = IIF( Empty( tcOpt) Or VarType(tcOpt) <> "C", "", ;
>	UPPER(ALLTRIM(tcOpt)))
>
>llRecursive = ("SUBDIR" $ lcOpt)
>llBasicData = ("BASIC"  $ lcOpt)
>
>IF llBasicData
>
>	CREATE CURSOR (lcCursorName) ( ;
>		Path C(60), ;
>		FileName C(64), ;
>		FileSize N(10), ;
>		FileDate D, ;
>		FileTime C(8), ;
>		FileAttr C(5))
>ELSE
>	CREATE CURSOR (lcCursorName) ( ;
>		Path C(60), ;
>		FileName C(64), ;
>		FileSize N(10), ;
>		FileDate D, ;
>		FileTime C(8), ;
>		FileAttr C(5), ;
>		FileExt C(5), ;
>		ProcCode C(3), ;
>		ProcDate D, ;
>		ProcTime C(8), ;
>		Note M)
>ENDIF
>
>INDEX ON path + FileName TAG pfn
>
>= LoadOneDir(lcCursorName, lcPath , @laPattern, lcAttributes, lnFlag, lcOpt, llRecursive)
>
>RETURN RECCOUNT(lcCursorName)
>
>FUNCTION LoadOneDir(tcCursorName, tcPath, taPattern, tcAttributes, tnFlag, tcOpt, tlRecursive)
>EXTERNAL ARRAY taPattern
>
>LOCAL lnFiles, i, laFileList[1], x, lcExtraAttr, llInclude, lcFileName, llBasicData
>llBasicData = ("BASIC"  $ tcOpt)
>
>IF NOT tlRecursive  OR ("D" $ tcAttributes)
>	lcAttributes = tcAttributes
>ELSE
>	lcAttributes = tcAttributes + "D"
>ENDIF
>
>lnFiles = ADIR(laFileList, tcPath + "*.*", lcAttributes, tnFlag)
>=ASORT(laFileList)
>
>FOR i=1 TO lnFiles
>	lcFileName = laFileList[i,1]
>	IF lcFileName = "."
>		LOOP
>	ENDIF
>
>	IF NOT ("." $ lcFileName)
>		lcFileName = lcFileName + "."
>	ENDIF
>	llInclude = .F.
>	FOR x=1 TO ALEN(taPattern)
>		IF LIKE(taPattern[x], lcFileName)
>			llInclude = .T.
>			EXIT
>		ENDIF
>	ENDFOR
>
>	IF llInclude AND ( NOT ("D" $ laFileList[i,5]) OR ("D" $ tcAttributes) )
>			INSERT INTO (tcCursorName) ;
>				( Path, FileName, FileSize, FileDate, FileTime, FileAttr) ;
>				VALUES (UPPER(tcPath), laFileList[i,1], ;
>				laFileList[i,2], laFileList[i,3], ;
>				laFileList[i,4], laFileList[i,5])
>		IF NOT llBasicData
>			REPLACE FileExt WITH JUSTEXT(laFileList[i,1])
>		ENDIF		
>	ENDIF
>
>	IF tlRecursive AND ("D" $ laFileList[i,5])
>		*susp
>		= LoadOneDir(tcCursorName, ADDBS(ALLTRIM(tcPath) + ALLTRIM(laFileList[i,1])), ;
>			@taPattern, tcAttributes, tnFlag, tcOpt, tlRecursive)
>	ENDIF
>ENDFOR
>
>
>RETURN
>ENDFUNC
>
>
>
>>I have a directory with many sub directories and wilsh to pull al list of the ".pdf" files within these directories.
>>
>>The documentation for the adir() function leads me to believe I can get this and have the array show the directory name with the file name.
>>
>>The documentation states you can ask for sub directoies but give no clue as to how.
>>
>>Is this part of the file skeleton or is this part of the attributes?
>>
>>any help will be appreciated.
>>
>>
>>Thanks in advance!


Great function Sergey,
always a pleasure to see your programs.
Thanks (Spasibo)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform