just get 7z files and past 24hrs

James Murrell
James Murrell used Ask the Experts™
on
is there a way to get this script to get just 7z files and where date modified or created is only 24 hours
Const ForWriting = 2
 
'Customize this variable with the appropriate folder
strRoot = "c:\files"
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReport = objFSO.CreateTextFile("report.csv", ForWriting)
 
objReport.WriteLine "Path,Date Created,Date Modified"
 
Set objStartFolder = objFSO.GetFolder(strRoot)
Set colFiles = objStartFolder.Files
 
For Each objFile in colFiles
        strPath = objFile.Path
        dtmCreated = objFile.DateCreated
        dtmModified = objFile.DateLastModified
        objReport.WriteLine strPath & "," & dtmCreated & "," & dtmModified
Next
 
ShowSubfolders(objStartFolder) 
 
objReport.Close
 
Sub ShowSubFolders(Folder)
    For Each objSubfolder in Folder.SubFolders
        Set objFolder = objFSO.GetFolder(objSubFolder.Path)
        Set colFiles = objFolder.Files
 
        For Each objFile in colFiles
                        strPath = objFile.Path
                        dtmCreated = objFile.DateCreated
                        dtmModified = objFile.DateLastModified
                        objReport.WriteLine strPath & "," & dtmCreated & "," & dtmModified
        Next
 
        ShowSubFolders objSubfolder
    Next
End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Const ForWriting = 2
 
''Customize this variable with the appropriate folder
strRoot = "C:\Users\Mike\Documents"
strExt = "7z"
intTimeDiff = 24
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReport = objFSO.CreateTextFile("report.csv", ForWriting)
 
objReport.WriteLine "Path,Date Created,Date Modified"
 
Set objStartFolder = objFSO.GetFolder(strRoot)
Set colFiles = objStartFolder.Files
 
WriteFiles
 
ShowSubfolders(objStartFolder) 
 
objReport.Close
 
Sub ShowSubFolders(Folder)
    For Each objSubfolder in Folder.SubFolders
        Set objFolder = objFSO.GetFolder(objSubFolder.Path)
        Set colFiles = objFolder.Files
 
		WriteFiles
 
        ShowSubFolders objSubfolder
    Next
End Sub
 
Sub WriteFiles
	For Each objFile in colFiles
			strPath = objFile.Path
			dtmCreated = objFile.DateCreated
			dtmModified = objFile.DateLastModified
			If Right(strPath, Len(strExt)) = strExt Then
				If DateDiff("h", dtmModified, Now) <= intTimeDiff Then
					objReport.WriteLine strPath & "," & dtmCreated & "," & dtmModified
				End If
			End If
	Next
End Sub

Open in new window

Commented:
Heres the code for a text document.  I would imagine you need to change text document to 7z ? Notice I have added :

& "," & dtype

to see what the type displays as
Const ForWriting = 2
 
'Customize this variable with the appropriate folder
strRoot = "c:\temp"
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReport = objFSO.CreateTextFile("report.csv", ForWriting)
 
objReport.WriteLine "Path,Date Created,Date Modified"
 
Set objStartFolder = objFSO.GetFolder(strRoot)
Set colFiles = objStartFolder.Files
 
For Each objFile in colFiles	
if objFile.DateLastModified > DateAdd("d", -1, Now()) then
	if objFile.Type = "Text Document" then
        strPath = objFile.Path
        dtmCreated = objFile.DateCreated
        dtmModified = objFile.DateLastModified
dtype = objFile.Type
        objReport.WriteLine strPath & "," & dtmCreated & "," & dtmModified & "," & dtype
end if	
end if
Next
 
ShowSubfolders(objStartFolder) 
 
objReport.Close
 
Sub ShowSubFolders(Folder)
    For Each objSubfolder in Folder.SubFolders
        Set objFolder = objFSO.GetFolder(objSubFolder.Path)
        Set colFiles = objFolder.Files
 
        For Each objFile in colFiles
		if objFile.DateLastModified > DateAdd("d", -1, Now()) then
			if objFile.Type = "Text Document" then
                        strPath = objFile.Path
                        dtmCreated = objFile.DateCreated
                        dtmModified = objFile.DateLastModified
                        objReport.WriteLine strPath & "," & dtmCreated & "," & dtmModified
		end if
		end if
        Next
 
        ShowSubFolders objSubfolder
    Next
End Sub

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial