| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 
 | Dim Folder2crawl(1)
Folder2crawl(0)="C:\Nouveau dossier\TEST"
Folder2crawl(1)="C:\Nouveau dossier\TEST2"
strOutput = "C:\wamp\www\site1\index_output.json"
 
' create file object
Set oFSO = CreateObject("Scripting.FileSystemObject")
' create output file
Set Output = oFSO.CreateTextFile(strOutput, True)
 
Output.WriteLine("{""folder"": [") 'start json file
' main loop
For i = 0 to UBound(Folder2crawl)
	strFolder = Folder2crawl(i)
	Set oFolder = oFSO.GetFolder(strFolder)
	' start new folder
	Output.WriteLine("{""file"": [")
 
	Set colFiles = oFolder.Files
	For Each objFile In colFiles ' loop to write each file
	  Output.WriteLine("{""name"": """ & Replace(objFile.Path,"\","\\") & """,""lastmodified"": """ & objFile.DateLastModified & """},")
	Next
	ShowSubFolders(oFolder) ' calls function for recursivity support
 
	' end new folder
	If i = UBound(Folder2crawl) Then ' if last folder not write ","	at the end
		Output.WriteLine("]}")
	Else
		Output.WriteLine("]},")
	End if	
Next
' end main loop
Output.WriteLine("]}") ' end json file
 
' function for recursivity support
Sub ShowSubFolders(oFolder)
  Set colFolders = oFolder.SubFolders
  For Each objSubFolder In colFolders
    Set colFiles = objSubFolder.Files
    For Each objFile In colFiles
	  Output.WriteLine("{""name"": """ & Replace(objFile.Path,"\","\\") & """,""lastmodified"": """ & objFile.DateLastModified & """},")
	Next
    ShowSubFolders(objSubFolder) ' calls function for recursivity support while subfolder exists
   Next
End Sub
 
' end of script - output file closure
Output.Close | 
Partager