Question : How to check a folder if file count has increased and identify file(s) by filename that increased the count

Hello,

I am looking for the best method to check a folder if file count has increased and identify the file(s) by filename that increased the file count in that folder\directory.
What is the best source to tap into for this?  I am looking at Performance Counter or WMI but would greatly appreciate any detail from the experts out there as to the best course of action.


Best Regards,


Charlie

Answer : How to check a folder if file count has increased and identify file(s) by filename that increased the count

Ok, this revision will write a tab-delimited list of new files and their creation dates to the file configured in the strReport variable.

1:
2:
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:
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
 
strFolder = "c:\files"
strList = "filelist.txt"
strReport = "report.txt"
 
Set objOldFiles = CreateObject("Scripting.Dictionary")
objOldFiles.CompareMode = VbTextCompare
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
If objFSO.FileExists(strReport) Then
    objFSO.DeleteFile strReport, True
End If
 
If objFSO.FileExists(strList) Then
    Set objList = objFSO.OpenTextFile(strList, ForReading)
    
    Do Until objList.AtEndOfStream
        arrLine = Split(objList.ReadLine, vbTab)
        objOldFiles.Add arrLine(0), arrLine(1)
    Loop
    
    objList.Close
End If
 
Set objList = objFSO.OpenTextFile(strList, ForWriting, True)
Set objFolder = objFSO.GetFolder(strFolder)
 
For Each objFile In objFolder.Files
    strName = objFile.Name
    dtmCreated = objFile.DateCreated
    objList.WriteLine strName & vbTab & dtmCreated
    
    If Not objOldFiles.Exists(strName) Then
        Set objReport = objFSO.OpenTextFile(strReport, ForAppending, True)
        objReport.WriteLine strName & vbTab & dtmCreated
        objReport.Close
    End If
Next
Random Solutions  
 
programming4us programming4us