Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
WSH and Subfolders of Subfolders
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00224547
Message ID:
00224737
Vues:
25
Hi Patric,

In order to accomplish this, you'll need to create a recursive routine. The following is an example UDF that will list all files for a given starting path, then call itself with any folders within that path:
*
* listfiles.prg
*

lparameters cFolder

if right(cFolder,1) # '\'
	cFolder = cFolder + '\'
endif

? cFolder

oFSO = CreateObject("scripting.FileSystemObject")

if oFSO.FolderExists(cFolder)

	oFolder = oFSO.GetFolder(cFolder)

	for each oFile in oFolder.Files
		? cFolder + oFile.Name 
	endfor

	for each oSubFolder in oFolder.SubFolders
		? cFolder + oSubFolder.Name
		listfiles(cFolder + oSubFolder.Name)
	endfor

else

	=messagebox("Path " + cFolder + " does not exist")

endif


>Hi all,
>
>I've been experimenting with the FileSystemObject and so far have really liked using it. I am attempting to get a list of filenames contained in certain folders, including subfolders that are several levels deep from the root folder. The code below works okay for getting the first level of files, but what modifications do I need to make to get ALL files contained on a particular drive/folder, including any files nested within multiple layers of subfilders? Any help is appreciated.
>
>The following code is a sample of what I'm working with so far (In my actual code, I am storing the filename and its complete path in a table rather than using a wait window to display it to the screen!):
>
>oFileSystem=CREATEOBJECT("scripting.filesystemobject")
>IF oFileSystem.FolderExists('C:\')
> oFolder=oFileSystem.GetFolder('C:\')
> FOR EACH oSubFolder in oFolder.SubFolders
> FOR EACH oFile in oSubFolder.Files
> WAIT WINDOW oFile.Name TIMEOUT 1
> ENDFOR
> ENDFOR
>ENDIF
>
>Thanks,
kenweber
GCom2 Solutions
Microsoft Certified Professional

Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform