Google Grupper understøtter ikke længere nye Usenet-opslag eller -abonnementer. Tidligere indhold er fortsat synligt.

move file more old 7 days

214 visninger
Gå til det første ulæste opslag

luca

ulæst,
15. nov. 2007, 06.09.0215.11.2007
til
Hi guys,
I would make a vbscript that move a file with more 7 days (from creation
date) in another folder. In the group WMI I have had a suggest.
I have find this script (with logparser installation):

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

Pegasus (MVP)

ulæst,
15. nov. 2007, 09.58.4515.11.2007
til
You already have a thread on the same subject in a different
newsgroup, with several detailed answers. Multi-posting the
same question elsewhere is not a good idea: It wastes everybody's
time. See here: http://www.blakjak.demon.co.uk/mul_crss.htm


"luca" <lu...@discussions.microsoft.com> wrote in message
news:9DA5DB5E-8B3E-4397...@microsoft.com...

McKirahan

ulæst,
15. nov. 2007, 10.11.3015.11.2007
til
"luca" <lu...@discussions.microsoft.com> wrote in message
news:9DA5DB5E-8B3E-4397...@microsoft.com...
> Hi guys,
> I would make a vbscript that move a file with more 7 days (from creation
> date) in another folder.

[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").


luca

ulæst,
15. nov. 2007, 11.37.0315.11.2007
til
Thank's!!!!!
This script is exactly script I need...

Goood

JanC

ulæst,
26. nov. 2007, 05.26.0026.11.2007
til
Nice script, I can almost use it. Is it possible to modify the script to
check for a file extension? I have move all .log files from a dir, but leave
all other files in there.

McKirahan

ulæst,
26. nov. 2007, 08.37.2026.11.2007
til
"JanC" <Ja...@discussions.microsoft.com> wrote in message
news:1E31B07B-79C1-4391...@microsoft.com...

> Nice script, I can almost use it. Is it possible to modify the script to
> check for a file extension? I have move all .log files from a dir, but
leave
> all other files in there.

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.


JanC

ulæst,
26. nov. 2007, 13.48.0126.11.2007
til
Thanks a lot! I need it to move files that are like 1 or 2 months old, but
just the log files. But i can manage to change that myself :)
0 nye opslag