Set objLogParser = CreateObject("MSUtil.LogQuery")
Set objInputFormat = CreateObject("MSUtil.LogQuery.FileSystemInputFormat")
objInputFormat.Recurse = 0
Set objOutputFormat = CreateObject("MSUtil.LogQuery.NativeOutputFormat")
objOutputFormat.rtp = -1
strQuery = "select path from c:\test\*.* where
div(sub(to_int(system_date()),to_int(to_date(creationtime))),86400)>7"
objLogParser.ExecuteBatch strQuery, objInputFormat, objOutputFormat
But now how move the file (fin with strQuery) in another folder?
Thank's
a lot
Luca
"luca" <lu...@discussions.microsoft.com> wrote in message
news:9DA5DB5E-8B3E-4397...@microsoft.com...
[snip]
"move a file" or "move all files"?
Will this help? Watch for word-wrap.
Option Explicit
'****
'* This VBScript moves all files created more than "cDAZ" days
'* from folder "cFOL" to folder "cMOV" and logs each to "cLOG".
'* (Note: the values of "cFOL" and "cMOV" should end with "\".)
'****
'*
'* Declare Constants
'*
Const cVBS = "Move7Days.vbs" '= script name
Const cLOG = "Move7Days.log" '= log filename
Const cFOL = "C:\Temp\" '= source folder
Const cMOV = "D:\Temp\" '= dest. folder
Const cDAZ = 7 '= # days
'*
'* Move_Files()
'*
Dim strMSG
strMSG = " files moved from " & cFOL & " to " & cMOV
MsgBox Move_Files(cFOL) & strMSG,vbInformation,cVBS
Function Move_Files(folder)
Move_Files = 0
'*
'* Declare Variables
'*
Dim strDAT
Dim intDAZ
Dim arrFIL()
ReDim arrFIL(0)
Dim intFIL
intFIL = 0
Dim strFIL
Dim intLEN
intLEN = 0
Dim strLOG
strLOG = "echo " & cVBS & " -- " & Now & vbCrLf
Dim dtmNOW
dtmNOW = Now
'*
'* Declare Objects
'*
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objGFO
Dim objGFI
'*
'* Validate folders
'*
If Not objFSO.FolderExists(cFOL) _
Or Not objFSO.FolderExists(cMOV) Then
MsgBox "A folder does not exist!",vbExclamation,cVBS
Exit Function
End If
'*
'* Process folder
'*
Set objGFO = objFSO.GetFolder(folder)
Set objGFI = objGFO.Files
'*
'* Select Files
'*
For Each strFIL In objGFI
strDAT = strFIL.DateCreated
intDAZ = DateDiff("d",strDAT,dtmNOW)
If intDAZ > cDAZ Then
intFIL = intFIL + 1
ReDim Preserve arrFIL(intFIL)
arrFIL(intFIL) = strFIL.Name
If intLEN < Len(strFIL.Name) Then
intLEN = Len(strFIL.Name)
End If
End If
Next
'*
'* Move Files
'*
For intFIL = 1 To UBound(arrFIL)
strFIL = arrFIL(intFIL)
objFSO.MoveFile folder & strFIL, cMOV & strFIL
strLOG = strLOG & "move " & folder & strFIL _
& Space(intLEN-Len(strFIL)+1) _
& cMOV & strFIL & vbCrLf
Next
'*
'* Destroy Objects
'*
Set objGFI = Nothing
Set objGFO = Nothing
strLOG = strLOG & "echo " & UBound(arrFIL) & " files moved"
objFSO.CreateTextFile(cLOG,True).Write(strLOG)
Set objFSO = Nothing
'*
'* Return Results
'*
Move_Files = UBound(arrFIL)
End Function
The log file is also a batch file that would
move the files when run from a command line;
(i.e. if objFSO.MoveFile() is commented out
and the extension ".log" was changed to ".bat").
Goood
Try changing this line:
If intDAZ > cDAZ Then
to
If intDAZ > cDAZ _
And LCase(Right(strFIL.Name,4)) = ".log" Then
However, you said "move all .log files" not just those
older than 7 days so you may need other changes.