Hello,
Hope someone can help. I am using this script to search for files older than a certain date and then move them to another folder. The script is working fine, however I need to only move a certain file extension.. e.g. .xls. Anyone know how I can modify this script to only move these file extensions?
Thanks
Dim objFSO, ofolder, objStream
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("scripting.filesystemobject")
Set objNet = CreateObject("WScript.NetWork")
Set FSO = CreateObject("Scripting.FileSystemObject")
set outfile = fso.createtextfile("Move-Result.txt",true)
SPath = "D:\Strata\Strata_Billing\"
CheckFolder(objFSO.getFolder(SPath))
Sub CheckFolder(objCurrentFolder)
Dim strTempL, strTempR, strSearchL, strSearchR, objNewFolder, objFile, strSize
Const OverwriteExisting = True
currDate = Date
dtmDate = Date - 60
strTargetDate = ConvDate(dtmDate)
For Each objFile In objCurrentFolder.Files
FileName = objFile
'WScript.Echo FileName & " " & strSize
strDate = ConvDate(objFile.DateCreated)
strDate = ConvDate(objFile.DateLastModified)
strSize = ConvertSize (objFile.Size)
If strDate < strTargetDate Then
objFSO.MoveFile FileName, "D:\Strata\Strata_Billing\Strata_Archive\"
outfile.writeline filename & ", ," & strSize
End If
Next
End Sub
Function ConvDate (sDate) 'Converts MM/DD/YYYY HH:MM:SS to string YYYYMMDD
strModifyDay = day(sDate)
If len(strModifyDay) < 2 Then
strModifyDay = "0" & strModifyDay
End If
strModifyMonth = Month(sDate)
If len(strModifyMonth) < 2 Then
strModifyMonth = "0" & strModifyMonth
End If
strModifyYear = Year(sDate)
ConvDate = strModifyYear & strModifyMonth & strModifyDay
End Function
Function ConvertSize(Size) 'Converts file size into KB,MB,GB,TB
Size = CSng(Replace(Size,",",""))
If Not VarType(Size) = vbSingle Then
ConvertSize = "SIZE INPUT ERROR"
Exit Function
End If
Suffix = " Bytes"
If Size >= 1024 Then suffix = " KB"
If Size >= 1048576 Then suffix = " MB"
If Size >= 1073741824 Then suffix = " GB"
If Size >= 1099511627776 Then suffix = " TB"
Select Case Suffix
Case " KB" Size = Round(Size / 1024, 1)
Case " MB" Size = Round(Size / 1048576, 1)
Case " GB" Size = Round(Size / 1073741824, 1)
Case " TB" Size = Round(Size / 1099511627776, 1)
End Select
ConvertSize = Size & Suffix
End Function
Hope someone can help. I am using this script to search for files older than a certain date and then move them to another folder. The script is working fine, however I need to only move a certain file extension.. e.g. .xls. Anyone know how I can modify this script to only move these file extensions?
Thanks
Dim objFSO, ofolder, objStream
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("scripting.filesystemobject")
Set objNet = CreateObject("WScript.NetWork")
Set FSO = CreateObject("Scripting.FileSystemObject")
set outfile = fso.createtextfile("Move-Result.txt",true)
SPath = "D:\Strata\Strata_Billing\"
CheckFolder(objFSO.getFolder(SPath))
Sub CheckFolder(objCurrentFolder)
Dim strTempL, strTempR, strSearchL, strSearchR, objNewFolder, objFile, strSize
Const OverwriteExisting = True
currDate = Date
dtmDate = Date - 60
strTargetDate = ConvDate(dtmDate)
For Each objFile In objCurrentFolder.Files
FileName = objFile
'WScript.Echo FileName & " " & strSize
strDate = ConvDate(objFile.DateCreated)
strDate = ConvDate(objFile.DateLastModified)
strSize = ConvertSize (objFile.Size)
If strDate < strTargetDate Then
objFSO.MoveFile FileName, "D:\Strata\Strata_Billing\Strata_Archive\"
outfile.writeline filename & ", ," & strSize
End If
Next
End Sub
Function ConvDate (sDate) 'Converts MM/DD/YYYY HH:MM:SS to string YYYYMMDD
strModifyDay = day(sDate)
If len(strModifyDay) < 2 Then
strModifyDay = "0" & strModifyDay
End If
strModifyMonth = Month(sDate)
If len(strModifyMonth) < 2 Then
strModifyMonth = "0" & strModifyMonth
End If
strModifyYear = Year(sDate)
ConvDate = strModifyYear & strModifyMonth & strModifyDay
End Function
Function ConvertSize(Size) 'Converts file size into KB,MB,GB,TB
Size = CSng(Replace(Size,",",""))
If Not VarType(Size) = vbSingle Then
ConvertSize = "SIZE INPUT ERROR"
Exit Function
End If
Suffix = " Bytes"
If Size >= 1024 Then suffix = " KB"
If Size >= 1048576 Then suffix = " MB"
If Size >= 1073741824 Then suffix = " GB"
If Size >= 1099511627776 Then suffix = " TB"
Select Case Suffix
Case " KB" Size = Round(Size / 1024, 1)
Case " MB" Size = Round(Size / 1048576, 1)
Case " GB" Size = Round(Size / 1073741824, 1)
Case " TB" Size = Round(Size / 1099511627776, 1)
End Select
ConvertSize = Size & Suffix
End Function