Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Capture a directory structure , including directories
Message
De
20/07/2000 04:56:17
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
20/07/2000 03:17:31
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00394769
Message ID:
00394788
Vues:
11
>What do I need ? To capture the structure of a directory . The problem is that I can't find a function to get the names of the subdirectories of the directory . All I get are the names of files .
>I can use ADIR() , DIRECTORY ... , GETDIR(), but all these functions and commands don't return the names of subdirectories, only the files .
>So , what can I do ?
>
>Thank you !
>Mihai Pascu


You could either use adir() with 'D' option or FileScriptingObject. Depends on your needs. Adir() doesn't access special folders but FSO does. You can test them :
*adir() version
function gettree
lparameters tcPath, tcCursorName
local lcTopDir
lcTopDir = sys(5)+curdir()
set defa to (tcPath)
create cursor (tcCursorName) ;
	(dirname c(127),attr c(5))
lcCurdir = sys(5)+curdir()
insert into (tcCursorName) ;
		(dirname) values (upper(tcPath))
=getsubdirs(lcCurdir, tcCursorName)
set default to (lcTopDir)
index on trim(dirname) tag dirname
locate for !empty(chrtran(attr,"AD.",""))
return !eof()

function getsubdirs
lparameters tcPath, tcCursorName
local lcCurDir, lnSubDirs, ix
local array laDirs[1]
lnSubdirs=adir(laDirs,tcPath+"*.*","HD")
for ix = 1 to lnSubDirs
    if laDirs[ix,1]#"." and "D"$laDirs[ix,5]
		insert into (tcCursorName) ;
			values (tcPath+laDirs[ix,1],laDirs[ix,5])
       	=getsubdirs(tcPath+laDirs[ix,1]+"\", tcCursorName)
    endif
endfor    


* FSO version - I can't remember who to credit for this
*!*	SET PROC TO FSOTree ADDITIVE
*!*	DECLARE aSubDirs[1]
*!*	? GetTreeUsingFSO(aSubDirs,'C:\')
*!*	disp memo like aSubDirs

* The first function of the pair just does the setup of the FSO and array;  do it yourself, 
* and you can get several paths' trees into the same array

SET PROC TO FSOTree ADDITIVE
LOCAL oFSO, oTopFolder, aSubDirs[1]
aSubDirs[1] = NULL
oFSO = CREATEOBJ('Scripting.FileSystemObject')
oTopFolder = oFSO.GetFolder('C:\Windows')
RecurseSubFoldersUsingFSO(oTopFolder,@aSubDirs)
oTopFolder = oFSO.GetFolder('C:\Program Files')
RecurseSubFoldersUsingFSO(oTopFolder,@aSubDirs)
create cursor dirlist (dirname c(254))
dimension aSubDirs[alen(aSubdirs),1]
append from array aSubDirs
browse

*Procedure file FSOTree
FUNCTION GetTreeUsingFSO
LPARAMETER taReturnArray, tcBaseFolder
EXTERNAL ARRAY taReturnArray
IF VARTYPE(tcBaseFolder) # 'C' OR ! DIRECTORY(FULLPATH(tcBaseFolder))
   tcBaseFolder = FULLPATH(CURDIR())
ENDIF
LOCAL oFSO, oTopFolder
oFSO = CREATEOBJ('Scripting.FileSystemObject')
oTopFolder = oFSO.GetFolder(tcBaseFolder)
DIMENSION taReturnArray[1]
taReturnArray = NULL
RecurseSubFoldersUsingFSO(oTopFolder,@taReturnArray)
RETURN ALEN(taReturnArray)

FUNCTION RecurseSubFoldersUsingFSO
LPARAMETERS toFolderObj, taReturnArray
EXTERNAL ARRAY taReturnArray
LOCAL nSizeOfArray,oSubFolders
nSizeOfArray = ALEN(taReturnArray) + IIF(ISNULL(taReturnArray[1]),0,1)
DIMENSION taReturnArray[nSizeOfArray]
taReturnArray[nSizeOfArray] = toFolderObj.path
oSubFolders = toFolderObj.SubFolders
FOR Each oFolder IN oSubFolders
* Added - Cetin
  if oFolder.Name # 'System Volume Information'
* Added - Cetin
    RecurseSubFoldersUsingFSO(oFolder,@taReturnArray)
  endif
ENDFOR
RETURN
Be carefull using FSO version. It even reaches to 'Sysem Volume Information' folder and trying further subdir search on it caues a crash. Better set a check on it and do not search subdirs when it's 'Sysem Volume Information'.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform