I have been using a vbScript that would create a file which would include the filenames of any files added to the Directory specified in the vbScript from there last time the vbScript was run . This has been working great but I am now in need of this file (value specified in strReport ) to include the filenames of those files that have:
a) been added to the directory
b) been deleted from the directory
c) been modified in that directory (want to track users that open files and change values in said file and save)
I have the vbScript below. Any thoughts or suggestions would be greatly appreciated.
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
strFolder = "c:\folder_to_monitor"
strList = "all_current_files.txt"
strReport = "new_files_added_report.txt"
Set objOldFiles = CreateObject("Scripting.Dictionary")
objOldFiles.CompareMode = VbTextCompare
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strReport) Then
objFSO.DeleteFile strReport, True
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)
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