-1

Im trying to read all *.p7c files stored in subfolders like this.

  1. C:\Cert_1\act\cert.p7c
  2. C:\Cert_2\act\cert.p7c
  3. C:\Cert_3\act\cert.p7c

and check the ValidTo Date. I only managed to read a single file in a specific folder.

Dim ScriptName
Dim Logdatei
Dim fso
Dim intTage

Const LogDir = "C:\Skript\CheckZert\LOGS"

Set fso = WScript.CreateObject("Scripting.FileSystemObject")
set cert = CreateObject("Chilkat_9_5_0.Cert")

ScriptName = WScript.ScriptName 
intTage = 14
Logdatei = Logfile(LogDir) 
success = cert.LoadFromFile("C:\Cert\Cert_1\act\cert.p7c")


    If (success <> 1) Then
        Call Writelog (cert.LastErrorText)
        WScript.Quit
    End If

    If DateDiff("d", Now, cert.ValidTo) < intTage Then                                                          
    
        Call Writelog ("Zertifikat: " & cert.SubjectDN)
        Call Writelog ("Gültig ab: " & cert.ValidFrom & " Gültig bis: " & cert.ValidTo)
        Call Writelog ("Seriennummer: " & cert.SerialNumber)    
        Call Writelog ("Zertifikat läuft ab am: " & cert.ValidTo)
    
    Else
    
        Call Writelog ("OK")
    
    End If

This works fine but im looking for a way to check all *.p7c files stored in the subfolders.

rel0aded0ne
  • 451
  • 2
  • 5
  • 17
  • Does this answer your question? [Apply existing VBS folder search to sub folders?](https://stackoverflow.com/a/41192464) – user692942 Jan 14 '21 at 14:21

1 Answers1

-2

Solution:

Sub ProcessFolder (Folder)
    
    For Each Fld in Folder.SubFolders
        ProcessFolder Fld
    Next
      
      For Each File In Folder.Files
        
        If Instr(1, File.Name, ".p7c", vbTextCompare ) > 0  Then
          cert.LoadFromFile(File.Path)
        
            If DateDiff("d", Now, cert.ValidTo) < intTage Then
        
                Call Writelog ("---------------------------------------") 
                Call Writelog ("Zertifikat: " & cert.SubjectDN)
                Call Writelog (File.Path)
                Call Writelog ("Gültig ab: " & cert.ValidFrom & " Gültig bis: " & cert.ValidTo)
                Call Writelog ("Seriennummer: " & cert.SerialNumber)    
                Call Writelog ("Zertifikat läuft am: " & cert.ValidTo & " ab")
          
            End if
          
        End If
    Next
    
End Sub 
rel0aded0ne
  • 451
  • 2
  • 5
  • 17
  • So the duplicate fixed your issue, instead of leaving another "here's how to recursively loop through subfolders" orphaned answer, just accept the duplicate close the question and go on with your day. – user692942 Jan 14 '21 at 14:19