Login | |
|
 |
RE: Creating a script to change logs files to the creat... - 9/26/2006 5:40:20 AM
|
|
 |
|
| |
ebgreen
Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
|
strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set FileList = objWMIService.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name='c:\logs'} Where " _ & "ResultClass = CIM_DataFile") For Each objFile In FileList If InStr(objFile.Name, "day") > 0 Then strDate = Left(objFile.CreationDate, 8) strNewName = objFile.Drive & objFile.Path & strDate & ".log" errResult = objFile.Rename(strNewname) End If Next
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Creating a script to change logs files to the creat... - 9/26/2006 7:49:32 PM
|
|
 |
|
| |
gdewrance
Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
|
how would you get it to run on a server share, it runs fine locally. e.g. c:\logs One other question where I have the name logon if the file name is Logon and I change it in the script to Logon it wont rename it, why's that? (it needs to be in lower case even though the name is in upper case) strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set FileList = objWMIService.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name='\\server\Share'} Where " _ & "ResultClass = CIM_DataFile") For Each objFile In FileList If InStr(objFile.Name, "logon") > 0 Then 'What does > 0 do strDate = Left(objFile.CreationDate, 8) 'Is this how old created in days? strNewName = objFile.Drive & objFile.Path & _ strDate & "." & "log" strNameCheck = Replace(strNewName, "\", "\\") End If i = 1 Do While True Set colFiles = objWMIService.ExecQuery _ ("Select * from Cim_Datafile Where Name = '" & strNameCheck & "'") If colFiles.Count = 0 Then errResult = objFile.Rename(strNewName) Exit Do Else i = i + 1 strNewName = objFile.Drive & objFile.Path & _ strDate & "_" & i & "." & "log" strNameCheck = Replace(strNewName, "\", "\\") End If Loop Next for devinw1 check out http://www.microsoft.com/technet/scriptcenter/resources/qanda/dec04/hey1209.mspx on how to move it. The scripting guy explains it.
|
|
| |
|
|
|
 |
RE: Creating a script to change logs files to the creat... - 9/27/2006 1:03:37 AM
|
|
 |
|
| |
ebgreen
Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
|
Did you try doing it the same way as moving it locally but using the UNC path? Experimentatation will teach you far faster than we can.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Creating a script to change logs files to the creat... - 9/27/2006 1:07:58 AM
|
|
 |
|
| |
gdewrance
Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
|
yip, tried that didnt work. Has it got somthing to do with Win32_Directory.Name=
|
|
| |
|
|
|
 |
RE: Creating a script to change logs files to the creat... - 9/27/2006 1:43:06 AM
|
|
 |
|
| |
ebgreen
Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
|
I would drop WMI altogether. I don't see where it is providing any added by using WMI. This script is written off the cuff so there may be (probably are) errors in it but it should get you satrted. Option Explicit Dim oFSO Dim oFile Dim colFiles Dim strDate Dim strNewName Set oFSO = CreateObject("Scripting.FileSystemObject") Set colFiles = oFSO.GetFolder("C:\Logs").Files For Each oFile in colFiles If InStr(oFile.Name, "day", 1) > 0 Then strDate = Left(oFile.CreationDate, 8) strNewName = strDate & "." & "log" oFile.Name = strNewName oFSO.MoveFile oFile.FullName, "\\SomeServer\SomeShare" End If Next
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Creating a script to change logs files to the creat... - 9/27/2006 3:08:05 AM
|
|
 |
|
| |
devinw1
Posts: 11
Score: 0
Joined: 9/26/2006
Status: offline
|
Dim oFSO, sSourceDir, sTargetDir, sFile, sNewName Set oFSO = CreateObject("Scripting.FileSystemObject") sSourceDir = "c:\logs" sTargetDir = "\\servername\test" For Each sFile In oFSO.GetFolder(sDir).Files If InStr(LCase(sFile),"day") <> 0 Then sNewName = Split(Replace(oFSO.GetFile(sFile).DateCreated,"/","")," ")(0) & ".log" If oFSO.FileExists(sTargetDir & "\" & sNewName) Then sNewName = Split(Replace(oFSO.GetFile(sFile).DateCreated,"/","")," ")(0) & "_1.log" End If oFSO.GetFile(sFile).Move sTargetDir & "\" & sNewName End If Next
_____________________________
Devin
|
|
| |
|
|
|
 |
RE: Creating a script to change logs files to the creat... - 9/27/2006 4:57:34 AM
|
|
 |
|
| |
DiGiTAL.SkReAM
Posts: 1194
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
|
Doggonnit! Sorry about all the errors, I should have stated that it was aircode. As you could probably tell. lol
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers) "It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
|
|
| |
|
|
|
|
|