'######################################################## '### Retrieve list of subfolders from a given folder ### '### ### '### (c) Dirk Pelzer 2004 ### '######################################################## Option Explicit Dim i Dim intRet Dim aryFolderList intRet = EnumerateFolders("C:\Temp", aryFolderList) Select Case intRet Case 1 wscript.echo "Error: Specified file alreday exists. Please specify a different name." & vbCRLF wscript.echo "Script aborted." wscript.quit(1) Case 2 wscript.echo "Error: The specified folder was empty." wscript.echo " Please verify that " & strFolder & " contains" & vbCRLF & _ " robocopy logs and you have sufficient permissions." & vbCRLF wscript.echo "Script aborted." wscript.quit(1) End Select wscript.echo "List of subfolders:" For i = 0 to uBound(aryFolderList) wscript.echo aryFolderList(i) Next '************************************************* ' EnumerateFolders '************************************************* Function EnumerateFolders(strFolder, aryFolderList) ' Returns an array of all subfolders of a specified folder ' EnumerateFolders = 0: success ' EnumerateFolders = 1: strFolder does not exist ' EnumerateFolders = 2: no subfolders found Dim strFolderList Dim fso, f, f1, fc, s strFolderList = "" Set fso = CreateObject("Scripting.FileSystemObject") If NOT (fso.FolderExists(strFolder)) Then EnumerateFolders = 1 'Specified folder does not exist Set fso = Nothing Exit Function End If Set f = fso.GetFolder(strFolder) Set fc = f.SubFolders For Each f1 in fc strFolderList = strFolderList & f1.name & ";" 'wscript.echo "strFolderList = " & strFolderList Next If right (strFolderList, 1) = ";" Then strFolderList = left(strFolderList, len(strFolderList)-1) aryFolderList = split (strFolderList, ";") If uBound(aryFolderList) >= 0 then EnumerateFolders = 0 'Folders found Else EnumerateFolders = 2 'No folders found End If Set fc = nothing Set f = nothing Set fso = nothing End Function