I only learn from my mistakes 
Author Message
 I only learn from my mistakes

I am trying to lear scriptiog and have put together the following script.  I
had parts of it working and I broke it again.  I someone would be so kind as
to point out the errors of my ways I would appreciate it.

It is my goal to get this to run on the workstations at work to remove the
TMP files from C:\ place them in a sub dir for removal later ( 14 days) with
another script that would use the log file created.

Kelly
====================
' ************* SearchMoveAndLogTMP.VBS ***************
Dim FSO
Dim ofolder
Dim objStream
Dim strSearch
Dim FileCount
Dim BackupPath

Const EVENT_OK = 0
Const EVENT_FAILED = 2

Drive = "C:\"
LogfileDir = "C:\StoreTMP\"
strSearch = ".tmp"
BackupPath = LogfileDir
FileCount = 0
Tday = Now()

' Parse today
FileMo = left(Tday,2)
FileDy = mid(Tday,4,2)
FileYr = mid(Tday,7,4)

On Error Resume Next

' Name LogFile to TMP(Date).log
Logfile = LogFileDir + "TMP" + FileMo + FileDy + FileYr + ".LOG"

Set FSO = CreateObject("scripting.filesystemobject")
'Set WSH = CreateObject("WScript.Shell")
Set WSH = Wscript.CreateObject("Wscript.Shell")

' Check for a backup folder
    If not FSO.FolderExists(BackupPath) then
       FSO.CreateFolder(BackupPath)
    WSH.sleep 1000
    End If

'Check for LogFile if not create the LogFile
  If not FSO.fileExists(LogFile) Then
    Set objStream = FSO.createtextfile(Logfile, True)
    WSH.sleep 1000  ' wait 1 second
    Set objLogFile = fso.OpenTextFile(Logfile, 8, True)
       WSH.sleep 1000  ' wait 1 second
 strOutput = TDay & " **
File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " & tDay &
vbCrLf
       objLogFile.writeline (strOutput)
  Else ' Open the file for Append
  Set objLogFile = fso.OpenTextFile(Logfile, 8, True)
       WSH.sleep 1000  ' wait 1 second
    strOutput = TDay & " **
File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " & tDay &
vbCrLf
       objLogFile.writeline (strOutput)
  End If
' GO SUB to CheckFolder
CheckFolder (FSO.getfolder(Drive)), objStream

' Log Event to Windows Event Log
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDiskDrives = objWMIService.ExecQuery _
    ("Select * from win32_perfformatteddata_perfdisk_logicaldisk")
For each objDisk in colDiskDrives
    strDriveSpace = objDisk.Name & " " & objDisk.FreeMegabytes _
        & VbCrLf
Next
strEventDescription = "File Search Completed." + vbCr + "Please check " &
Logfile & _
       " for details." & vbCrLf & " Number of Files Coppied: " & FileCount &
vbCrLf & _
       objNetwork.UserDomain & "\" & objNetwork.ComputerName _
       & " by user " & objNetwork.UserName & _
       ". Free space on each drive is: " & strDriveSpace
WSH.LogEvent EVENT_OK, strEventDescription

Message = "File Search Completed." + vbCr + "Please check " & Logfile & "
for details." & vbCrLf
Message = Message + " Number of Files Coppied: " & FileCount
MsgBox Message

Set objLogFile = Nothing
Set objStream = Nothing
Set strSearch = Nothing
Set FileCount = Nothing
Set BackupPath = Nothing
WScript.Quit(0)
' ************************* END OF SCRIPT ***************************

' CheckFolder Subroutine
Sub CheckFolder(objCurrentFolder, objLogFile)
    WSH.Popup Message, 1,"Entering CheckFolder"
    Dim strTemp
    Dim strOutput
    Dim objNewFolder
    Dim objFile
    Dim objStream

       For Each objFile In objCurrentFolder.Files
           strTemp = Right(objFile.Name, 4)
                If UCase(strTemp) = UCase(strSearch) Then
                    'Got one
        strOutput = CStr(objFile.Name) + "," + CStr(objFile.Path) _
             + "," + CStr(objFile.Size) + "," + CStr(objFile.Type) + "," _
             + CStr(objFile.datelastaccessed) + vbCrLf
                    objLogFile.writeline strOutput
                   ' Move the file to BackupPath
                   FileCount = FileCount + 1
                   FSO.CopyFile objFile.Name, BackupPath
'                  objFile.Name.Delete
                End If
       Next

       'Recurse through all of the folders
       For Each objNewFolder In objCurrentFolder.subFolders
'           If left(objNewFolder,10) = "C:\StoreTM" Or left(objNewFolder,10)
= "C:\RECYCLE" Then
                 WSH.Popup Message, 1,"Skipping C:\StoreTMP or C:\RECYCLE
Directory" & vbCrLf & " Processed " & FileCount & " Files."
'              else
                CheckFolder objNewFolder, objLogFile
'           end if
       Next

End Sub



Thu, 16 Dec 2004 09:46:57 GMT  
 I only learn from my mistakes
Remove the 'On Error Resume Next' and let the script tell you what's wrong.  It's a cardinal sin to enable inline error handling and then never check for errors.

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Thu, 16 Dec 2004 10:26:45 GMT  
 I only learn from my mistakes
Taking a look at this, Kelly.

By the way, something you might want to do: when getting code ready to post, try
limiting the lines to 60-65 characters everywhere possible and using line
continuations if you need to.  This makes it easier for people to check without
having to do a lot of line unwrapping and maybe coming up with the wrong error.

What is it doing wrong - where is it throwing an error right now, and what kind?
If you aren't getting any errors due to the "On Error Resume Next", what
symptoms does it exhibit?

Quote:

> I am trying to lear scriptiog and have put together the following script.  I
> had parts of it working and I broke it again.  I someone would be so kind as
> to point out the errors of my ways I would appreciate it.

> It is my goal to get this to run on the workstations at work to remove the
> TMP files from C:\ place them in a sub dir for removal later ( 14 days) with
> another script that would use the log file created.

> Kelly
> ====================
> ' ************* SearchMoveAndLogTMP.VBS ***************
> Dim FSO
> Dim ofolder
> Dim objStream
> Dim strSearch
> Dim FileCount
> Dim BackupPath

> Const EVENT_OK = 0
> Const EVENT_FAILED = 2

> Drive = "C:\"
> LogfileDir = "C:\StoreTMP\"
> strSearch = ".tmp"
> BackupPath = LogfileDir
> FileCount = 0
> Tday = Now()

> ' Parse today
> FileMo = left(Tday,2)
> FileDy = mid(Tday,4,2)
> FileYr = mid(Tday,7,4)

> On Error Resume Next

> ' Name LogFile to TMP(Date).log
> Logfile = LogFileDir + "TMP" + FileMo + FileDy + FileYr + ".LOG"

> Set FSO = CreateObject("scripting.filesystemobject")
> 'Set WSH = CreateObject("WScript.Shell")
> Set WSH = Wscript.CreateObject("Wscript.Shell")

> ' Check for a backup folder
>     If not FSO.FolderExists(BackupPath) then
>        FSO.CreateFolder(BackupPath)
>     WSH.sleep 1000
>     End If

> 'Check for LogFile if not create the LogFile
>   If not FSO.fileExists(LogFile) Then
>     Set objStream = FSO.createtextfile(Logfile, True)
>     WSH.sleep 1000  ' wait 1 second
>     Set objLogFile = fso.OpenTextFile(Logfile, 8, True)
>        WSH.sleep 1000  ' wait 1 second
>  strOutput = TDay & " **
> File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " & tDay &
> vbCrLf
>        objLogFile.writeline (strOutput)
>   Else ' Open the file for Append
>   Set objLogFile = fso.OpenTextFile(Logfile, 8, True)
>        WSH.sleep 1000  ' wait 1 second
>     strOutput = TDay & " **
> File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " & tDay &
> vbCrLf
>        objLogFile.writeline (strOutput)
>   End If
> ' GO SUB to CheckFolder
> CheckFolder (FSO.getfolder(Drive)), objStream

> ' Log Event to Windows Event Log
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" _
>     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> Set colDiskDrives = objWMIService.ExecQuery _
>     ("Select * from win32_perfformatteddata_perfdisk_logicaldisk")
> For each objDisk in colDiskDrives
>     strDriveSpace = objDisk.Name & " " & objDisk.FreeMegabytes _
>         & VbCrLf
> Next
> strEventDescription = "File Search Completed." + vbCr + "Please check " &
> Logfile & _
>        " for details." & vbCrLf & " Number of Files Coppied: " & FileCount &
> vbCrLf & _
>        objNetwork.UserDomain & "\" & objNetwork.ComputerName _
>        & " by user " & objNetwork.UserName & _
>        ". Free space on each drive is: " & strDriveSpace
> WSH.LogEvent EVENT_OK, strEventDescription

> Message = "File Search Completed." + vbCr + "Please check " & Logfile & "
> for details." & vbCrLf
> Message = Message + " Number of Files Coppied: " & FileCount
> MsgBox Message

> Set objLogFile = Nothing
> Set objStream = Nothing
> Set strSearch = Nothing
> Set FileCount = Nothing
> Set BackupPath = Nothing
> WScript.Quit(0)
> ' ************************* END OF SCRIPT ***************************

> ' CheckFolder Subroutine
> Sub CheckFolder(objCurrentFolder, objLogFile)
>     WSH.Popup Message, 1,"Entering CheckFolder"
>     Dim strTemp
>     Dim strOutput
>     Dim objNewFolder
>     Dim objFile
>     Dim objStream

>        For Each objFile In objCurrentFolder.Files
>            strTemp = Right(objFile.Name, 4)
>                 If UCase(strTemp) = UCase(strSearch) Then
>                     'Got one
>         strOutput = CStr(objFile.Name) + "," + CStr(objFile.Path) _
>              + "," + CStr(objFile.Size) + "," + CStr(objFile.Type) + "," _
>              + CStr(objFile.datelastaccessed) + vbCrLf
>                     objLogFile.writeline strOutput
>                    ' Move the file to BackupPath
>                    FileCount = FileCount + 1
>                    FSO.CopyFile objFile.Name, BackupPath
> '                  objFile.Name.Delete
>                 End If
>        Next

>        'Recurse through all of the folders
>        For Each objNewFolder In objCurrentFolder.subFolders
> '           If left(objNewFolder,10) = "C:\StoreTM" Or left(objNewFolder,10)
> = "C:\RECYCLE" Then
>                  WSH.Popup Message, 1,"Skipping C:\StoreTMP or C:\RECYCLE
> Directory" & vbCrLf & " Processed " & FileCount & " Files."
> '              else
>                 CheckFolder objNewFolder, objLogFile
> '           end if
>        Next

> End Sub



Thu, 16 Dec 2004 10:29:14 GMT  
 I only learn from my mistakes
Thanks for the quick reply(s).
It is not giving me an error it is however not finding any TMP files.  It
seems to be skipping a chunk of the code that deals with the SUB ...which
searches for the TMP files.

Thanks for the help.
Kelly



Quote:
> Taking a look at this, Kelly.

> By the way, something you might want to do: when getting code ready to
post, try
> limiting the lines to 60-65 characters everywhere possible and using line
> continuations if you need to.  This makes it easier for people to check
without
> having to do a lot of line unwrapping and maybe coming up with the wrong
error.

> What is it doing wrong - where is it throwing an error right now, and what
kind?
> If you aren't getting any errors due to the "On Error Resume Next", what
> symptoms does it exhibit?


> > I am trying to lear scriptiog and have put together the following
script.  I
> > had parts of it working and I broke it again.  I someone would be so
kind as
> > to point out the errors of my ways I would appreciate it.

> > It is my goal to get this to run on the workstations at work to remove
the
> > TMP files from C:\ place them in a sub dir for removal later ( 14 days)
with
> > another script that would use the log file created.

> > Kelly
> > ====================
> > ' ************* SearchMoveAndLogTMP.VBS ***************
> > Dim FSO
> > Dim ofolder
> > Dim objStream
> > Dim strSearch
> > Dim FileCount
> > Dim BackupPath

> > Const EVENT_OK = 0
> > Const EVENT_FAILED = 2

> > Drive = "C:\"
> > LogfileDir = "C:\StoreTMP\"
> > strSearch = ".tmp"
> > BackupPath = LogfileDir
> > FileCount = 0
> > Tday = Now()

> > ' Parse today
> > FileMo = left(Tday,2)
> > FileDy = mid(Tday,4,2)
> > FileYr = mid(Tday,7,4)

> > On Error Resume Next

> > ' Name LogFile to TMP(Date).log
> > Logfile = LogFileDir + "TMP" + FileMo + FileDy + FileYr + ".LOG"

> > Set FSO = CreateObject("scripting.filesystemobject")
> > 'Set WSH = CreateObject("WScript.Shell")
> > Set WSH = Wscript.CreateObject("Wscript.Shell")

> > ' Check for a backup folder
> >     If not FSO.FolderExists(BackupPath) then
> >        FSO.CreateFolder(BackupPath)
> >     WSH.sleep 1000
> >     End If

> > 'Check for LogFile if not create the LogFile
> >   If not FSO.fileExists(LogFile) Then
> >     Set objStream = FSO.createtextfile(Logfile, True)
> >     WSH.sleep 1000  ' wait 1 second
> >     Set objLogFile = fso.OpenTextFile(Logfile, 8, True)
> >        WSH.sleep 1000  ' wait 1 second
> >  strOutput = TDay & " **
> > File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " & tDay
&
> > vbCrLf
> >        objLogFile.writeline (strOutput)
> >   Else ' Open the file for Append
> >   Set objLogFile = fso.OpenTextFile(Logfile, 8, True)
> >        WSH.sleep 1000  ' wait 1 second
> >     strOutput = TDay & " **
> > File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " & tDay
&
> > vbCrLf
> >        objLogFile.writeline (strOutput)
> >   End If
> > ' GO SUB to CheckFolder
> > CheckFolder (FSO.getfolder(Drive)), objStream

> > ' Log Event to Windows Event Log
> > strComputer = "."
> > Set objWMIService = GetObject("winmgmts:" _
> >     & "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
> > Set colDiskDrives = objWMIService.ExecQuery _
> >     ("Select * from win32_perfformatteddata_perfdisk_logicaldisk")
> > For each objDisk in colDiskDrives
> >     strDriveSpace = objDisk.Name & " " & objDisk.FreeMegabytes _
> >         & VbCrLf
> > Next
> > strEventDescription = "File Search Completed." + vbCr + "Please check "
&
> > Logfile & _
> >        " for details." & vbCrLf & " Number of Files Coppied: " &
FileCount &
> > vbCrLf & _
> >        objNetwork.UserDomain & "\" & objNetwork.ComputerName _
> >        & " by user " & objNetwork.UserName & _
> >        ". Free space on each drive is: " & strDriveSpace
> > WSH.LogEvent EVENT_OK, strEventDescription

> > Message = "File Search Completed." + vbCr + "Please check " & Logfile &
"
> > for details." & vbCrLf
> > Message = Message + " Number of Files Coppied: " & FileCount
> > MsgBox Message

> > Set objLogFile = Nothing
> > Set objStream = Nothing
> > Set strSearch = Nothing
> > Set FileCount = Nothing
> > Set BackupPath = Nothing
> > WScript.Quit(0)
> > ' ************************* END OF SCRIPT ***************************

> > ' CheckFolder Subroutine
> > Sub CheckFolder(objCurrentFolder, objLogFile)
> >     WSH.Popup Message, 1,"Entering CheckFolder"
> >     Dim strTemp
> >     Dim strOutput
> >     Dim objNewFolder
> >     Dim objFile
> >     Dim objStream

> >        For Each objFile In objCurrentFolder.Files
> >            strTemp = Right(objFile.Name, 4)
> >                 If UCase(strTemp) = UCase(strSearch) Then
> >                     'Got one
> >         strOutput = CStr(objFile.Name) + "," + CStr(objFile.Path) _
> >              + "," + CStr(objFile.Size) + "," + CStr(objFile.Type) + ","
_
> >              + CStr(objFile.datelastaccessed) + vbCrLf
> >                     objLogFile.writeline strOutput
> >                    ' Move the file to BackupPath
> >                    FileCount = FileCount + 1
> >                    FSO.CopyFile objFile.Name, BackupPath
> > '                  objFile.Name.Delete
> >                 End If
> >        Next

> >        'Recurse through all of the folders
> >        For Each objNewFolder In objCurrentFolder.subFolders
> > '           If left(objNewFolder,10) = "C:\StoreTM" Or

left(objNewFolder,10)

- Show quoted text -

Quote:
> > = "C:\RECYCLE" Then
> >                  WSH.Popup Message, 1,"Skipping C:\StoreTMP or
C:\RECYCLE
> > Directory" & vbCrLf & " Processed " & FileCount & " Files."
> > '              else
> >                 CheckFolder objNewFolder, objLogFile
> > '           end if
> >        Next

> > End Sub



Thu, 16 Dec 2004 10:39:46 GMT  
 I only learn from my mistakes
Kill the error handling, you'll see a few errors.

Here are 3 things that you want to deal with to start out.

(1) Remove the Set WSH = WScript.CreateObject("WScript.Shell") line.  You don't
ever use the WScript.Shell object, and WSH is a reserved word anyway - you can't
make it into a variable.

(2) Change the WSH.Sleep lines to WScript.Sleep.  WScript is a "built in"
object, and calling WScript.Sleep is just like calling WScript.CreateObject -
you don't need to set a variable reference to WScript, WScript is available
right away.

(3) Same thing  with WSH.Popup - change to WScript.Popup.


Quote:
> Thanks for the quick reply(s).
> It is not giving me an error it is however not finding any TMP files.  It
> seems to be skipping a chunk of the code that deals with the SUB ...which
> searches for the TMP files.

> Thanks for the help.
> Kelly



> > Taking a look at this, Kelly.

> > By the way, something you might want to do: when getting code ready to
> post, try
> > limiting the lines to 60-65 characters everywhere possible and using line
> > continuations if you need to.  This makes it easier for people to check
> without
> > having to do a lot of line unwrapping and maybe coming up with the wrong
> error.

> > What is it doing wrong - where is it throwing an error right now, and what
> kind?
> > If you aren't getting any errors due to the "On Error Resume Next", what
> > symptoms does it exhibit?


> > > I am trying to lear scriptiog and have put together the following
> script.  I
> > > had parts of it working and I broke it again.  I someone would be so
> kind as
> > > to point out the errors of my ways I would appreciate it.

> > > It is my goal to get this to run on the workstations at work to remove
> the
> > > TMP files from C:\ place them in a sub dir for removal later ( 14 days)
> with
> > > another script that would use the log file created.

> > > Kelly
> > > ====================
> > > ' ************* SearchMoveAndLogTMP.VBS ***************
> > > Dim FSO
> > > Dim ofolder
> > > Dim objStream
> > > Dim strSearch
> > > Dim FileCount
> > > Dim BackupPath

> > > Const EVENT_OK = 0
> > > Const EVENT_FAILED = 2

> > > Drive = "C:\"
> > > LogfileDir = "C:\StoreTMP\"
> > > strSearch = ".tmp"
> > > BackupPath = LogfileDir
> > > FileCount = 0
> > > Tday = Now()

> > > ' Parse today
> > > FileMo = left(Tday,2)
> > > FileDy = mid(Tday,4,2)
> > > FileYr = mid(Tday,7,4)

> > > On Error Resume Next

> > > ' Name LogFile to TMP(Date).log
> > > Logfile = LogFileDir + "TMP" + FileMo + FileDy + FileYr + ".LOG"

> > > Set FSO = CreateObject("scripting.filesystemobject")
> > > 'Set WSH = CreateObject("WScript.Shell")
> > > Set WSH = Wscript.CreateObject("Wscript.Shell")

> > > ' Check for a backup folder
> > >     If not FSO.FolderExists(BackupPath) then
> > >        FSO.CreateFolder(BackupPath)
> > >     WSH.sleep 1000
> > >     End If

> > > 'Check for LogFile if not create the LogFile
> > >   If not FSO.fileExists(LogFile) Then
> > >     Set objStream = FSO.createtextfile(Logfile, True)
> > >     WSH.sleep 1000  ' wait 1 second
> > >     Set objLogFile = fso.OpenTextFile(Logfile, 8, True)
> > >        WSH.sleep 1000  ' wait 1 second
> > >  strOutput = TDay & " **
> > > File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " & tDay
> &
> > > vbCrLf
> > >        objLogFile.writeline (strOutput)
> > >   Else ' Open the file for Append
> > >   Set objLogFile = fso.OpenTextFile(Logfile, 8, True)
> > >        WSH.sleep 1000  ' wait 1 second
> > >     strOutput = TDay & " **
> > > File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " & tDay
> &
> > > vbCrLf
> > >        objLogFile.writeline (strOutput)
> > >   End If
> > > ' GO SUB to CheckFolder
> > > CheckFolder (FSO.getfolder(Drive)), objStream

> > > ' Log Event to Windows Event Log
> > > strComputer = "."
> > > Set objWMIService = GetObject("winmgmts:" _
> > >     & "{impersonationLevel=impersonate}!\\" & strComputer &
> "\root\cimv2")
> > > Set colDiskDrives = objWMIService.ExecQuery _
> > >     ("Select * from win32_perfformatteddata_perfdisk_logicaldisk")
> > > For each objDisk in colDiskDrives
> > >     strDriveSpace = objDisk.Name & " " & objDisk.FreeMegabytes _
> > >         & VbCrLf
> > > Next
> > > strEventDescription = "File Search Completed." + vbCr + "Please check "
> &
> > > Logfile & _
> > >        " for details." & vbCrLf & " Number of Files Coppied: " &
> FileCount &
> > > vbCrLf & _
> > >        objNetwork.UserDomain & "\" & objNetwork.ComputerName _
> > >        & " by user " & objNetwork.UserName & _
> > >        ". Free space on each drive is: " & strDriveSpace
> > > WSH.LogEvent EVENT_OK, strEventDescription

> > > Message = "File Search Completed." + vbCr + "Please check " & Logfile &
> "
> > > for details." & vbCrLf
> > > Message = Message + " Number of Files Coppied: " & FileCount
> > > MsgBox Message

> > > Set objLogFile = Nothing
> > > Set objStream = Nothing
> > > Set strSearch = Nothing
> > > Set FileCount = Nothing
> > > Set BackupPath = Nothing
> > > WScript.Quit(0)
> > > ' ************************* END OF SCRIPT ***************************

> > > ' CheckFolder Subroutine
> > > Sub CheckFolder(objCurrentFolder, objLogFile)
> > >     WSH.Popup Message, 1,"Entering CheckFolder"
> > >     Dim strTemp
> > >     Dim strOutput
> > >     Dim objNewFolder
> > >     Dim objFile
> > >     Dim objStream

> > >        For Each objFile In objCurrentFolder.Files
> > >            strTemp = Right(objFile.Name, 4)
> > >                 If UCase(strTemp) = UCase(strSearch) Then
> > >                     'Got one
> > >         strOutput = CStr(objFile.Name) + "," + CStr(objFile.Path) _
> > >              + "," + CStr(objFile.Size) + "," + CStr(objFile.Type) + ","
> _
> > >              + CStr(objFile.datelastaccessed) + vbCrLf
> > >                     objLogFile.writeline strOutput
> > >                    ' Move the file to BackupPath
> > >                    FileCount = FileCount + 1
> > >                    FSO.CopyFile objFile.Name, BackupPath
> > > '                  objFile.Name.Delete
> > >                 End If
> > >        Next

> > >        'Recurse through all of the folders
> > >        For Each objNewFolder In objCurrentFolder.subFolders
> > > '           If left(objNewFolder,10) = "C:\StoreTM" Or
> left(objNewFolder,10)
> > > = "C:\RECYCLE" Then
> > >                  WSH.Popup Message, 1,"Skipping C:\StoreTMP or
> C:\RECYCLE
> > > Directory" & vbCrLf & " Processed " & FileCount & " Files."
> > > '              else
> > >                 CheckFolder objNewFolder, objLogFile
> > > '           end if
> > >        Next

> > > End Sub



Thu, 16 Dec 2004 10:49:10 GMT  
 I only learn from my mistakes
I am reposting the script after correcting the script.  I am however getting
a "C:\WSH\SearchAndLog.vbs(129, 20) Microsoft VBScript runtime error: Object
required: 'objLogFile'"   I have tried several thing but it is obovious I
don't understand why I am getting this error.

Thanks for your help.
Kelly
============================================
Dim FSO
Dim ofolder
Dim objStream
Dim objLogFile
Dim strSearch
Dim FileCount
Dim BackupPath

Const EVENT_OK = 0
Const EVENT_FAILED = 2

Drive = "C:\"
LogfileDir = "C:\StoreTMP\"
strSearch = ".tmp"
BackupPath = LogfileDir
FileCount = 0
Tday = Now()
button1 = vbOKonly ' vbOKOnly

' Parse Tday Month
If mid(Tday,2,1)="/" Then
     FileMo = Left(Tday,1)
   Else
     FileMo = Left(Tday,2)
end If
' Parse Tday Day
If len(FileMo) = 1 And mid(Tday,4,1)="/" Then
     FileDy = Mid(tday,3,1)
   Else
     FileDy = Mid(tday,3,2)
End If

If len(FileMo) = 2 And mid(Tday,5,1)="/" Then
     FileDy = Mid(tday,4,1)
  Else
     FileDy = Mid(tday,4,2)
End If
' Parse Tday Year
if len(FileMo) = 1 And Len(FileDy) = 1 Then
     FileYr =  Mid(tday,5,4)
End If
if len(FileMo) = 2 And Len(FileDy) = 1 Then
     FileYr =  Mid(tday,6,4)
End If
if len(FileMo) = 2 And Len(FileDy) = 2 Then
     FileYr =  Mid(tday,7,4)
End If

' On Error Resume Next

' Name LogFile to TMP(Date).log
Logfile = LogFileDir + "TMP" + FileMo + FileDy + FileYr + ".LOG"

Set FSO = CreateObject("scripting.filesystemobject")
' Set objWSH = WScript.CreateObject("Wscript.Shell")

' Check for a backup folder if no folder create it
    If not FSO.FolderExists(BackupPath) then
       FSO.CreateFolder(BackupPath)
    WScript.sleep 1000
    End If

'Check for LogFile if not create the LogFile
' NOTE OpenTextFile For Reading = 1, For Writing = 2, For Appending = 8
  If not FSO.fileExists(LogFile) Then
    Set objStream = FSO.createtextfile(Logfile, True)
    WScript.sleep 1000  ' wait 1 second - Open file for Append
    Set objLogFile = FSO.OpenTextFile(Logfile, 8, True)
       WScript.sleep 1000  ' wait 1 second
 strOutput = TDay & " **
File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " & tDay &
vbCrLf
       objLogFile.writeline (strOutput)
  Else ' Open the file for Append
    Set objLogFile = FSO.OpenTextFile(Logfile, 8, True)
       WScript.sleep 1000  ' wait 1 second
    strOutput = TDay & " **
File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " & tDay &
vbCrLf
       objLogFile.writeline (strOutput)
  End If

' GO SUB to CheckFolder
CheckFolder (FSO.getfolder(Drive)), objStream

' Log Event to Windows Event Log
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & _
     "\root\cimv2")
Set colDiskDrives = objWMIService.ExecQuery _
    ("Select * from win32_perfformatteddata_perfdisk_logicaldisk")
For each objDisk in colDiskDrives
    strDriveSpace = objDisk.Name & " " & objDisk.FreeMegabytes _
        & VbCrLf
Next
strEventDescription = "File Search Completed." + vbCr + _
"Please check " & Logfile & " for details." & vbCrLf & _
" Number of Files Coppied: " & FileCount & vbCrLf & _
objNetwork.UserDomain & "\" & objNetwork.ComputerName _
& " by user " & objNetwork.UserName & _
". Free space on each drive is: " & strDriveSpace
WScript.LogEvent EVENT_OK, strEventDescription

Message = "File Search Completed." + vbCr + "Please check " & Logfile & _
" for details." & vbCrLf
Message = Message + " Number of Files Coppied: " & FileCount
MsgBox Message

Set objStream = Nothing
Set strSearch = Nothing
Set FileCount = Nothing
Set BackupPath = Nothing
WScript.Quit(0)
' ************************* END OF SCRIPT ***************************

' CheckFolder Subroutine
Sub CheckFolder(objCurrentFolder, objLogFile)
'    WScript.Popup Message, 1,"Entering CheckFolder"
    Dim strTemp
    Dim strOutput
    Dim objNewFolder
    Dim objFile
    Dim objStream

       For Each objFile In objCurrentFolder.Files
           strTemp = Right(objFile.Name, 4)
                If UCase(strTemp) = UCase(strSearch) Then
                    'Got one
        strOutput = CStr(objFile.Name) + "," + CStr(objFile.Path) _
             + "," + CStr(objFile.Size) + "," + CStr(objFile.Type) + "," _
             + CStr(objFile.datelastaccessed) + vbCrLf
                   objLogFile.writeline(strOutput)
                   ' Move the file to BackupPath
                   FileCount = FileCount + 1
                   FSO.CopyFile objFile.Name, BackupPath
'                  objFile.Name.Delete
                End If
       Next

       'Recurse through all of the folders
       For Each objNewFolder In objCurrentFolder.subFolders
           If left(objNewFolder,10) = "C:\StoreTM" Or _
           left(objNewFolder,10) = "C:\RECYCLE" Then
                 WScript.Popup Message, 1,"Skipping C:\StoreTMP _
                 or C:\RECYCLE Directory" & vbCrLf & " Processed "_
                  & FileCount & " Files."
              else
                CheckFolder objNewFolder, objLogFile
           end if
       Next

End Sub
==========================================================


Quote:
> Kill the error handling, you'll see a few errors.

> Here are 3 things that you want to deal with to start out.

> (1) Remove the Set WSH = WScript.CreateObject("WScript.Shell") line.  You
don't
> ever use the WScript.Shell object, and WSH is a reserved word anyway - you
can't
> make it into a variable.

> (2) Change the WSH.Sleep lines to WScript.Sleep.  WScript is a "built in"
> object, and calling WScript.Sleep is just like calling

WScript.CreateObject -
Quote:
> you don't need to set a variable reference to WScript, WScript is
available
> right away.

> (3) Same thing  with WSH.Popup - change to WScript.Popup.



> > Thanks for the quick reply(s).
> > It is not giving me an error it is however not finding any TMP files.
It
> > seems to be skipping a chunk of the code that deals with the SUB
...which
> > searches for the TMP files.

> > Thanks for the help.
> > Kelly



> > > Taking a look at this, Kelly.

> > > By the way, something you might want to do: when getting code ready to
> > post, try
> > > limiting the lines to 60-65 characters everywhere possible and using
line
> > > continuations if you need to.  This makes it easier for people to
check
> > without
> > > having to do a lot of line unwrapping and maybe coming up with the
wrong
> > error.

> > > What is it doing wrong - where is it throwing an error right now, and
what
> > kind?
> > > If you aren't getting any errors due to the "On Error Resume Next",
what
> > > symptoms does it exhibit?


> > > > I am trying to lear scriptiog and have put together the following
> > script.  I
> > > > had parts of it working and I broke it again.  I someone would be so
> > kind as
> > > > to point out the errors of my ways I would appreciate it.

> > > > It is my goal to get this to run on the workstations at work to
remove
> > the
> > > > TMP files from C:\ place them in a sub dir for removal later ( 14
days)
> > with
> > > > another script that would use the log file created.

> > > > Kelly
> > > > ====================
> > > > ' ************* SearchMoveAndLogTMP.VBS ***************
> > > > Dim FSO
> > > > Dim ofolder
> > > > Dim objStream
> > > > Dim strSearch
> > > > Dim FileCount
> > > > Dim BackupPath

> > > > Const EVENT_OK = 0
> > > > Const EVENT_FAILED = 2

> > > > Drive = "C:\"
> > > > LogfileDir = "C:\StoreTMP\"
> > > > strSearch = ".tmp"
> > > > BackupPath = LogfileDir
> > > > FileCount = 0
> > > > Tday = Now()

> > > > ' Parse today
> > > > FileMo = left(Tday,2)
> > > > FileDy = mid(Tday,4,2)
> > > > FileYr = mid(Tday,7,4)

> > > > On Error Resume Next

> > > > ' Name LogFile to TMP(Date).log
> > > > Logfile = LogFileDir + "TMP" + FileMo + FileDy + FileYr + ".LOG"

> > > > Set FSO = CreateObject("scripting.filesystemobject")
> > > > 'Set WSH = CreateObject("WScript.Shell")
> > > > Set WSH = Wscript.CreateObject("Wscript.Shell")

> > > > ' Check for a backup folder
> > > >     If not FSO.FolderExists(BackupPath) then
> > > >        FSO.CreateFolder(BackupPath)
> > > >     WSH.sleep 1000
> > > >     End If

> > > > 'Check for LogFile if not create the LogFile
> > > >   If not FSO.fileExists(LogFile) Then
> > > >     Set objStream = FSO.createtextfile(Logfile, True)
> > > >     WSH.sleep 1000  ' wait 1 second
> > > >     Set objLogFile = fso.OpenTextFile(Logfile, 8, True)
> > > >        WSH.sleep 1000  ' wait 1 second
> > > >  strOutput = TDay & " **
> > > > File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " &
tDay
> > &
> > > > vbCrLf
> > > >        objLogFile.writeline (strOutput)
> > > >   Else ' Open the file for Append
> > > >   Set objLogFile = fso.OpenTextFile(Logfile, 8, True)
> > > >        WSH.sleep 1000  ' wait 1 second
> > > >     strOutput = TDay & " **
> > > > File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " &
tDay
> > &
> > > > vbCrLf
> > > >        objLogFile.writeline (strOutput)
> > > >   End If
> > > > ' GO SUB to CheckFolder
> > > > CheckFolder (FSO.getfolder(Drive)), objStream

> > > > ' Log Event to Windows Event Log
> > > > strComputer = "."
> > > > Set objWMIService = GetObject("winmgmts:" _
> > > >     & "{impersonationLevel=impersonate}!\\" & strComputer &
> > "\root\cimv2")
> > > > Set colDiskDrives = objWMIService.ExecQuery _
> > > >     ("Select * from win32_perfformatteddata_perfdisk_logicaldisk")
> > > > For each objDisk in colDiskDrives
> > > >     strDriveSpace = objDisk.Name & " " & objDisk.FreeMegabytes _
> > > >         & VbCrLf
> > > > Next
> > > > strEventDescription

...

read more »



Sat, 18 Dec 2004 00:49:45 GMT  
 I only learn from my mistakes
This probably should be approached somewhat differently; here's why.

You set some references to the log file via FSO in your global code; now
you're trying to access it locally.  You are probably also having
problems with your mixed references to the same file which you open in
different ways at different points.

There's good news and bad news.  The good news is you really are making
some handy use of the features of FSO.  The bad news is, it looks like
spaghetti right now.

I recall trying to work with FSO and logging the first time over a year
ago; my code looked very much like yours does now.

To get things straightened out, let's try to look at the tasks you want
to accomplish in your code first; we will need to retrace a couple of
steps, but you will understand what's happening much better - and your
code will be more compact as well.

From reading it, here's what I think I see you are trying to do (I'm not
writing these in any particular order).  Could you comment on this
summary of your goals?

(1) You want to log the available space on each drive to the event log
when the script is run.

(2) You want to find all .TMP files not in the recycle bin (or already
in the special directory) and move them to a special directory.

(3) You want to log the names of all files moved.

(4) I'm not seeing where in your code this is done, but you want to
delete the files after a certain number of days.

--
Please respond in the newsgroup.  I've still got unread email from the
week Win95 was released, if that tells you anything.
http://www.bittnet.com/winremote
http://www.bittnet.com/scripting


Quote:
> I am reposting the script after correcting the script.  I am however
getting
> a "C:\WSH\SearchAndLog.vbs(129, 20) Microsoft VBScript runtime error:
Object
> required: 'objLogFile'"   I have tried several thing but it is
obovious I
> don't understand why I am getting this error.

> Thanks for your help.
> Kelly
> ============================================
> Dim FSO
> Dim ofolder
> Dim objStream
> Dim objLogFile
> Dim strSearch
> Dim FileCount
> Dim BackupPath

> Const EVENT_OK = 0
> Const EVENT_FAILED = 2

> Drive = "C:\"
> LogfileDir = "C:\StoreTMP\"
> strSearch = ".tmp"
> BackupPath = LogfileDir
> FileCount = 0
> Tday = Now()
> button1 = vbOKonly ' vbOKOnly

> ' Parse Tday Month
> If mid(Tday,2,1)="/" Then
>      FileMo = Left(Tday,1)
>    Else
>      FileMo = Left(Tday,2)
> end If
> ' Parse Tday Day
> If len(FileMo) = 1 And mid(Tday,4,1)="/" Then
>      FileDy = Mid(tday,3,1)
>    Else
>      FileDy = Mid(tday,3,2)
> End If

> If len(FileMo) = 2 And mid(Tday,5,1)="/" Then
>      FileDy = Mid(tday,4,1)
>   Else
>      FileDy = Mid(tday,4,2)
> End If
> ' Parse Tday Year
> if len(FileMo) = 1 And Len(FileDy) = 1 Then
>      FileYr =  Mid(tday,5,4)
> End If
> if len(FileMo) = 2 And Len(FileDy) = 1 Then
>      FileYr =  Mid(tday,6,4)
> End If
> if len(FileMo) = 2 And Len(FileDy) = 2 Then
>      FileYr =  Mid(tday,7,4)
> End If

> ' On Error Resume Next

> ' Name LogFile to TMP(Date).log
> Logfile = LogFileDir + "TMP" + FileMo + FileDy + FileYr + ".LOG"

> Set FSO = CreateObject("scripting.filesystemobject")
> ' Set objWSH = WScript.CreateObject("Wscript.Shell")

> ' Check for a backup folder if no folder create it
>     If not FSO.FolderExists(BackupPath) then
>        FSO.CreateFolder(BackupPath)
>     WScript.sleep 1000
>     End If

> 'Check for LogFile if not create the LogFile
> ' NOTE OpenTextFile For Reading = 1, For Writing = 2, For Appending =
8
>   If not FSO.fileExists(LogFile) Then
>     Set objStream = FSO.createtextfile(Logfile, True)
>     WScript.sleep 1000  ' wait 1 second - Open file for Append
>     Set objLogFile = FSO.OpenTextFile(Logfile, 8, True)
>        WScript.sleep 1000  ' wait 1 second
>  strOutput = TDay & " **
> File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " &
tDay &
> vbCrLf
>        objLogFile.writeline (strOutput)
>   Else ' Open the file for Append
>     Set objLogFile = FSO.OpenTextFile(Logfile, 8, True)
>        WScript.sleep 1000  ' wait 1 second
>     strOutput = TDay & " **
> File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " &
tDay &
> vbCrLf
>        objLogFile.writeline (strOutput)
>   End If

> ' GO SUB to CheckFolder
> CheckFolder (FSO.getfolder(Drive)), objStream

> ' Log Event to Windows Event Log
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" _
>     & "{impersonationLevel=impersonate}!\\" & strComputer & _
>      "\root\cimv2")
> Set colDiskDrives = objWMIService.ExecQuery _
>     ("Select * from win32_perfformatteddata_perfdisk_logicaldisk")
> For each objDisk in colDiskDrives
>     strDriveSpace = objDisk.Name & " " & objDisk.FreeMegabytes _
>         & VbCrLf
> Next
> strEventDescription = "File Search Completed." + vbCr + _
> "Please check " & Logfile & " for details." & vbCrLf & _
> " Number of Files Coppied: " & FileCount & vbCrLf & _
> objNetwork.UserDomain & "\" & objNetwork.ComputerName _
> & " by user " & objNetwork.UserName & _
> ". Free space on each drive is: " & strDriveSpace
> WScript.LogEvent EVENT_OK, strEventDescription

> Message = "File Search Completed." + vbCr + "Please check " & Logfile
& _
> " for details." & vbCrLf
> Message = Message + " Number of Files Coppied: " & FileCount
> MsgBox Message

> Set objStream = Nothing
> Set strSearch = Nothing
> Set FileCount = Nothing
> Set BackupPath = Nothing
> WScript.Quit(0)
> ' ************************* END OF SCRIPT ***************************

> ' CheckFolder Subroutine
> Sub CheckFolder(objCurrentFolder, objLogFile)
> '    WScript.Popup Message, 1,"Entering CheckFolder"
>     Dim strTemp
>     Dim strOutput
>     Dim objNewFolder
>     Dim objFile
>     Dim objStream

>        For Each objFile In objCurrentFolder.Files
>            strTemp = Right(objFile.Name, 4)
>                 If UCase(strTemp) = UCase(strSearch) Then
>                     'Got one
>         strOutput = CStr(objFile.Name) + "," + CStr(objFile.Path) _
>              + "," + CStr(objFile.Size) + "," + CStr(objFile.Type) +
"," _
>              + CStr(objFile.datelastaccessed) + vbCrLf
>                    objLogFile.writeline(strOutput)
>                    ' Move the file to BackupPath
>                    FileCount = FileCount + 1
>                    FSO.CopyFile objFile.Name, BackupPath
> '                  objFile.Name.Delete
>                 End If
>        Next

>        'Recurse through all of the folders
>        For Each objNewFolder In objCurrentFolder.subFolders
>            If left(objNewFolder,10) = "C:\StoreTM" Or _
>            left(objNewFolder,10) = "C:\RECYCLE" Then
>                  WScript.Popup Message, 1,"Skipping C:\StoreTMP _
>                  or C:\RECYCLE Directory" & vbCrLf & " Processed "_
>                   & FileCount & " Files."
>               else
>                 CheckFolder objNewFolder, objLogFile
>            end if
>        Next

> End Sub
> ==========================================================


> > Kill the error handling, you'll see a few errors.

> > Here are 3 things that you want to deal with to start out.

> > (1) Remove the Set WSH = WScript.CreateObject("WScript.Shell") line.
You
> don't
> > ever use the WScript.Shell object, and WSH is a reserved word
anyway - you
> can't
> > make it into a variable.

> > (2) Change the WSH.Sleep lines to WScript.Sleep.  WScript is a
"built in"
> > object, and calling WScript.Sleep is just like calling
> WScript.CreateObject -
> > you don't need to set a variable reference to WScript, WScript is
> available
> > right away.

> > (3) Same thing  with WSH.Popup - change to WScript.Popup.



> > > Thanks for the quick reply(s).
> > > It is not giving me an error it is however not finding any TMP
files.
> It
> > > seems to be skipping a chunk of the code that deals with the SUB
> ...which
> > > searches for the TMP files.

> > > Thanks for the help.
> > > Kelly



> > > > Taking a look at this, Kelly.

> > > > By the way, something you might want to do: when getting code
ready to
> > > post, try
> > > > limiting the lines to 60-65 characters everywhere possible and
using
> line
> > > > continuations if you need to.  This makes it easier for people
to
> check
> > > without
> > > > having to do a lot of line unwrapping and maybe coming up with
the
> wrong
> > > error.

> > > > What is it doing wrong - where is it throwing an error right
now, and
> what
> > > kind?
> > > > If you aren't getting any errors due to the "On Error Resume
Next",
> what
> > > > symptoms does it exhibit?


> > > > > I am trying to lear scriptiog and have put together the
following
> > > script.  I
> > > > > had parts of it working and I broke it again.  I someone would
be so
> > > kind as
> > > > > to point out the errors of my ways I would appreciate it.

> > > > > It is my goal to get this to run on the workstations at work
to
> remove
> > > the
> > > > > TMP files from C:\ place them in a sub dir for removal later
( 14
> days)
> > > with
> > > > > another script that would use the log file created.

> > > > > Kelly
> > > > > ====================
> > > > > ' ************* SearchMoveAndLogTMP.VBS ***************
> > > > > Dim FSO
> > > > > Dim ofolder
> > > > > Dim objStream
> > > > > Dim strSearch
> > > > > Dim FileCount
> > > > > Dim BackupPath

> > > > > Const EVENT_OK = 0
> > > > > Const EVENT_FAILED = 2

> > > > > Drive = "C:\"
> > > > > LogfileDir = "C:\StoreTMP\"

...

read more »



Sat, 18 Dec 2004 01:32:07 GMT  
 I only learn from my mistakes

Quote:

> I am reposting the script after correcting the script.  I am however
> getting a "C:\WSH\SearchAndLog.vbs(129, 20) Microsoft VBScript
> runtime error: Object required: 'objLogFile'"   I have tried several
> thing but it is obovious I don't understand why I am getting this
> error.

I don't see where you ever create objLogFile as a textstream instance...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Sat, 18 Dec 2004 01:32:18 GMT  
 I only learn from my mistakes
Your right I did not Michael.  The only thing I did was open the log file
for an append (at the top).

Kelly



Quote:

> I am reposting the script after correcting the script.  I am however
> getting a "C:\WSH\SearchAndLog.vbs(129, 20) Microsoft VBScript
> runtime error: Object required: 'objLogFile'"   I have tried several
> thing but it is obovious I don't understand why I am getting this
> error.

I don't see where you ever create objLogFile as a textstream instance...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Sat, 18 Dec 2004 01:46:14 GMT  
 I only learn from my mistakes
Thanks for time and effort Alex.

Your right I am trying to:

1. Find all TMP file
2. Move them to a TMP directory (for later cleanup)
3. Create a log file of what has been moved
4. Summarize the operation, collect some information about the local
    computer and write it to the event log.

Kelly



Quote:
> This probably should be approached somewhat differently; here's why.

> You set some references to the log file via FSO in your global code; now
> you're trying to access it locally.  You are probably also having
> problems with your mixed references to the same file which you open in
> different ways at different points.

> There's good news and bad news.  The good news is you really are making
> some handy use of the features of FSO.  The bad news is, it looks like
> spaghetti right now.

> I recall trying to work with FSO and logging the first time over a year
> ago; my code looked very much like yours does now.

> To get things straightened out, let's try to look at the tasks you want
> to accomplish in your code first; we will need to retrace a couple of
> steps, but you will understand what's happening much better - and your
> code will be more compact as well.

> From reading it, here's what I think I see you are trying to do (I'm not
> writing these in any particular order).  Could you comment on this
> summary of your goals?

> (1) You want to log the available space on each drive to the event log
> when the script is run.

> (2) You want to find all .TMP files not in the recycle bin (or already
> in the special directory) and move them to a special directory.

> (3) You want to log the names of all files moved.

> (4) I'm not seeing where in your code this is done, but you want to
> delete the files after a certain number of days.

> --
> Please respond in the newsgroup.  I've still got unread email from the
> week Win95 was released, if that tells you anything.
> http://www.bittnet.com/winremote
> http://www.bittnet.com/scripting



> > I am reposting the script after correcting the script.  I am however
> getting
> > a "C:\WSH\SearchAndLog.vbs(129, 20) Microsoft VBScript runtime error:
> Object
> > required: 'objLogFile'"   I have tried several thing but it is
> obovious I
> > don't understand why I am getting this error.

> > Thanks for your help.
> > Kelly
> > ============================================
> > Dim FSO
> > Dim ofolder
> > Dim objStream
> > Dim objLogFile
> > Dim strSearch
> > Dim FileCount
> > Dim BackupPath

> > Const EVENT_OK = 0
> > Const EVENT_FAILED = 2

> > Drive = "C:\"
> > LogfileDir = "C:\StoreTMP\"
> > strSearch = ".tmp"
> > BackupPath = LogfileDir
> > FileCount = 0
> > Tday = Now()
> > button1 = vbOKonly ' vbOKOnly

> > ' Parse Tday Month
> > If mid(Tday,2,1)="/" Then
> >      FileMo = Left(Tday,1)
> >    Else
> >      FileMo = Left(Tday,2)
> > end If
> > ' Parse Tday Day
> > If len(FileMo) = 1 And mid(Tday,4,1)="/" Then
> >      FileDy = Mid(tday,3,1)
> >    Else
> >      FileDy = Mid(tday,3,2)
> > End If

> > If len(FileMo) = 2 And mid(Tday,5,1)="/" Then
> >      FileDy = Mid(tday,4,1)
> >   Else
> >      FileDy = Mid(tday,4,2)
> > End If
> > ' Parse Tday Year
> > if len(FileMo) = 1 And Len(FileDy) = 1 Then
> >      FileYr =  Mid(tday,5,4)
> > End If
> > if len(FileMo) = 2 And Len(FileDy) = 1 Then
> >      FileYr =  Mid(tday,6,4)
> > End If
> > if len(FileMo) = 2 And Len(FileDy) = 2 Then
> >      FileYr =  Mid(tday,7,4)
> > End If

> > ' On Error Resume Next

> > ' Name LogFile to TMP(Date).log
> > Logfile = LogFileDir + "TMP" + FileMo + FileDy + FileYr + ".LOG"

> > Set FSO = CreateObject("scripting.filesystemobject")
> > ' Set objWSH = WScript.CreateObject("Wscript.Shell")

> > ' Check for a backup folder if no folder create it
> >     If not FSO.FolderExists(BackupPath) then
> >        FSO.CreateFolder(BackupPath)
> >     WScript.sleep 1000
> >     End If

> > 'Check for LogFile if not create the LogFile
> > ' NOTE OpenTextFile For Reading = 1, For Writing = 2, For Appending =
> 8
> >   If not FSO.fileExists(LogFile) Then
> >     Set objStream = FSO.createtextfile(Logfile, True)
> >     WScript.sleep 1000  ' wait 1 second - Open file for Append
> >     Set objLogFile = FSO.OpenTextFile(Logfile, 8, True)
> >        WScript.sleep 1000  ' wait 1 second
> >  strOutput = TDay & " **
> > File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " &
> tDay &
> > vbCrLf
> >        objLogFile.writeline (strOutput)
> >   Else ' Open the file for Append
> >     Set objLogFile = FSO.OpenTextFile(Logfile, 8, True)
> >        WScript.sleep 1000  ' wait 1 second
> >     strOutput = TDay & " **
> > File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " &
> tDay &
> > vbCrLf
> >        objLogFile.writeline (strOutput)
> >   End If

> > ' GO SUB to CheckFolder
> > CheckFolder (FSO.getfolder(Drive)), objStream

> > ' Log Event to Windows Event Log
> > strComputer = "."
> > Set objWMIService = GetObject("winmgmts:" _
> >     & "{impersonationLevel=impersonate}!\\" & strComputer & _
> >      "\root\cimv2")
> > Set colDiskDrives = objWMIService.ExecQuery _
> >     ("Select * from win32_perfformatteddata_perfdisk_logicaldisk")
> > For each objDisk in colDiskDrives
> >     strDriveSpace = objDisk.Name & " " & objDisk.FreeMegabytes _
> >         & VbCrLf
> > Next
> > strEventDescription = "File Search Completed." + vbCr + _
> > "Please check " & Logfile & " for details." & vbCrLf & _
> > " Number of Files Coppied: " & FileCount & vbCrLf & _
> > objNetwork.UserDomain & "\" & objNetwork.ComputerName _
> > & " by user " & objNetwork.UserName & _
> > ". Free space on each drive is: " & strDriveSpace
> > WScript.LogEvent EVENT_OK, strEventDescription

> > Message = "File Search Completed." + vbCr + "Please check " & Logfile
> & _
> > " for details." & vbCrLf
> > Message = Message + " Number of Files Coppied: " & FileCount
> > MsgBox Message

> > Set objStream = Nothing
> > Set strSearch = Nothing
> > Set FileCount = Nothing
> > Set BackupPath = Nothing
> > WScript.Quit(0)
> > ' ************************* END OF SCRIPT ***************************

> > ' CheckFolder Subroutine
> > Sub CheckFolder(objCurrentFolder, objLogFile)
> > '    WScript.Popup Message, 1,"Entering CheckFolder"
> >     Dim strTemp
> >     Dim strOutput
> >     Dim objNewFolder
> >     Dim objFile
> >     Dim objStream

> >        For Each objFile In objCurrentFolder.Files
> >            strTemp = Right(objFile.Name, 4)
> >                 If UCase(strTemp) = UCase(strSearch) Then
> >                     'Got one
> >         strOutput = CStr(objFile.Name) + "," + CStr(objFile.Path) _
> >              + "," + CStr(objFile.Size) + "," + CStr(objFile.Type) +
> "," _
> >              + CStr(objFile.datelastaccessed) + vbCrLf
> >                    objLogFile.writeline(strOutput)
> >                    ' Move the file to BackupPath
> >                    FileCount = FileCount + 1
> >                    FSO.CopyFile objFile.Name, BackupPath
> > '                  objFile.Name.Delete
> >                 End If
> >        Next

> >        'Recurse through all of the folders
> >        For Each objNewFolder In objCurrentFolder.subFolders
> >            If left(objNewFolder,10) = "C:\StoreTM" Or _
> >            left(objNewFolder,10) = "C:\RECYCLE" Then
> >                  WScript.Popup Message, 1,"Skipping C:\StoreTMP _
> >                  or C:\RECYCLE Directory" & vbCrLf & " Processed "_
> >                   & FileCount & " Files."
> >               else
> >                 CheckFolder objNewFolder, objLogFile
> >            end if
> >        Next

> > End Sub
> > ==========================================================


> > > Kill the error handling, you'll see a few errors.

> > > Here are 3 things that you want to deal with to start out.

> > > (1) Remove the Set WSH = WScript.CreateObject("WScript.Shell") line.
> You
> > don't
> > > ever use the WScript.Shell object, and WSH is a reserved word
> anyway - you
> > can't
> > > make it into a variable.

> > > (2) Change the WSH.Sleep lines to WScript.Sleep.  WScript is a
> "built in"
> > > object, and calling WScript.Sleep is just like calling
> > WScript.CreateObject -
> > > you don't need to set a variable reference to WScript, WScript is
> > available
> > > right away.

> > > (3) Same thing  with WSH.Popup - change to WScript.Popup.



> > > > Thanks for the quick reply(s).
> > > > It is not giving me an error it is however not finding any TMP
> files.
> > It
> > > > seems to be skipping a chunk of the code that deals with the SUB
> > ...which
> > > > searches for the TMP files.

> > > > Thanks for the help.
> > > > Kelly



> > > > > Taking a look at this, Kelly.

> > > > > By the way, something you might want to do: when getting code
> ready to
> > > > post, try
> > > > > limiting the lines to 60-65 characters everywhere possible and
> using
> > line
> > > > > continuations if you need to.  This makes it easier for people
> to
> > check
> > > > without
> > > > > having to do a lot of line unwrapping and maybe coming up with
> the
> > wrong
> > > > error.

> > > > > What is it doing wrong - where is it throwing an error right
> now, and
> > what
> > > > kind?
> > > > > If you aren't getting any errors due to the "On Error Resume
> Next",
> > what
> > > > > symptoms does it exhibit?



...

read more »



Sat, 18 Dec 2004 01:50:52 GMT  
 I only learn from my mistakes
Kelly,

I can see where a large chunk of your problem is coming from.  The
primary issue here is that there is no simple mechanism for making a
collection of files based on some criteria for an entire drive; you have
to "build your own", so to speak.  This is a daunting task for even
{*filter*} scripters.

I'm looking at how this can be revised a bit - it's a problem definitely
ripe for solving - but I wanted to ask something else.  I've noticed
that you make use of WMI; is WMI pretty much installed on all the
systems you are checking? And what os version are they running?  There
may be a dramatically simpler way of doing this.

--
Please respond in the newsgroup.  I've still got unread email from the
week Win95 was released, if that tells you anything.
http://www.*-*-*.com/
http://www.*-*-*.com/


Quote:
> Thanks for time and effort Alex.

> Your right I am trying to:

> 1. Find all TMP file
> 2. Move them to a TMP directory (for later cleanup)
> 3. Create a log file of what has been moved
> 4. Summarize the operation, collect some information about the local
>     computer and write it to the event log.

> Kelly



> > This probably should be approached somewhat differently; here's why.

> > You set some references to the log file via FSO in your global code;
now
> > you're trying to access it locally.  You are probably also having
> > problems with your mixed references to the same file which you open
in
> > different ways at different points.

> > There's good news and bad news.  The good news is you really are
making
> > some handy use of the features of FSO.  The bad news is, it looks
like
> > spaghetti right now.

> > I recall trying to work with FSO and logging the first time over a
year
> > ago; my code looked very much like yours does now.

> > To get things straightened out, let's try to look at the tasks you
want
> > to accomplish in your code first; we will need to retrace a couple
of
> > steps, but you will understand what's happening much better - and
your
> > code will be more compact as well.

> > From reading it, here's what I think I see you are trying to do (I'm
not
> > writing these in any particular order).  Could you comment on this
> > summary of your goals?

> > (1) You want to log the available space on each drive to the event
log
> > when the script is run.

> > (2) You want to find all .TMP files not in the recycle bin (or
already
> > in the special directory) and move them to a special directory.

> > (3) You want to log the names of all files moved.

> > (4) I'm not seeing where in your code this is done, but you want to
> > delete the files after a certain number of days.

> > --
> > Please respond in the newsgroup.  I've still got unread email from
the
> > week Win95 was released, if that tells you anything.
> > http://www.*-*-*.com/
> > http://www.*-*-*.com/



> > > I am reposting the script after correcting the script.  I am
however
> > getting
> > > a "C:\WSH\SearchAndLog.vbs(129, 20) Microsoft VBScript runtime
error:
> > Object
> > > required: 'objLogFile'"   I have tried several thing but it is
> > obovious I
> > > don't understand why I am getting this error.

> > > Thanks for your help.
> > > Kelly
> > > ============================================
> > > Dim FSO
> > > Dim ofolder
> > > Dim objStream
> > > Dim objLogFile
> > > Dim strSearch
> > > Dim FileCount
> > > Dim BackupPath

> > > Const EVENT_OK = 0
> > > Const EVENT_FAILED = 2

> > > Drive = "C:\"
> > > LogfileDir = "C:\StoreTMP\"
> > > strSearch = ".tmp"
> > > BackupPath = LogfileDir
> > > FileCount = 0
> > > Tday = Now()
> > > button1 = vbOKonly ' vbOKOnly

> > > ' Parse Tday Month
> > > If mid(Tday,2,1)="/" Then
> > >      FileMo = Left(Tday,1)
> > >    Else
> > >      FileMo = Left(Tday,2)
> > > end If
> > > ' Parse Tday Day
> > > If len(FileMo) = 1 And mid(Tday,4,1)="/" Then
> > >      FileDy = Mid(tday,3,1)
> > >    Else
> > >      FileDy = Mid(tday,3,2)
> > > End If

> > > If len(FileMo) = 2 And mid(Tday,5,1)="/" Then
> > >      FileDy = Mid(tday,4,1)
> > >   Else
> > >      FileDy = Mid(tday,4,2)
> > > End If
> > > ' Parse Tday Year
> > > if len(FileMo) = 1 And Len(FileDy) = 1 Then
> > >      FileYr =  Mid(tday,5,4)
> > > End If
> > > if len(FileMo) = 2 And Len(FileDy) = 1 Then
> > >      FileYr =  Mid(tday,6,4)
> > > End If
> > > if len(FileMo) = 2 And Len(FileDy) = 2 Then
> > >      FileYr =  Mid(tday,7,4)
> > > End If

> > > ' On Error Resume Next

> > > ' Name LogFile to TMP(Date).log
> > > Logfile = LogFileDir + "TMP" + FileMo + FileDy + FileYr + ".LOG"

> > > Set FSO = CreateObject("scripting.filesystemobject")
> > > ' Set objWSH = WScript.CreateObject("Wscript.Shell")

> > > ' Check for a backup folder if no folder create it
> > >     If not FSO.FolderExists(BackupPath) then
> > >        FSO.CreateFolder(BackupPath)
> > >     WScript.sleep 1000
> > >     End If

> > > 'Check for LogFile if not create the LogFile
> > > ' NOTE OpenTextFile For Reading = 1, For Writing = 2, For
Appending =
> > 8
> > >   If not FSO.fileExists(LogFile) Then
> > >     Set objStream = FSO.createtextfile(Logfile, True)
> > >     WScript.sleep 1000  ' wait 1 second - Open file for Append
> > >     Set objLogFile = FSO.OpenTextFile(Logfile, 8, True)
> > >        WScript.sleep 1000  ' wait 1 second
> > >  strOutput = TDay & " **
> > > File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " &
> > tDay &
> > > vbCrLf
> > >        objLogFile.writeline (strOutput)
> > >   Else ' Open the file for Append
> > >     Set objLogFile = FSO.OpenTextFile(Logfile, 8, True)
> > >        WScript.sleep 1000  ' wait 1 second
> > >     strOutput = TDay & " **
> > > File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " &
> > tDay &
> > > vbCrLf
> > >        objLogFile.writeline (strOutput)
> > >   End If

> > > ' GO SUB to CheckFolder
> > > CheckFolder (FSO.getfolder(Drive)), objStream

> > > ' Log Event to Windows Event Log
> > > strComputer = "."
> > > Set objWMIService = GetObject("winmgmts:" _
> > >     & "{impersonationLevel=impersonate}!\\" & strComputer & _
> > >      "\root\cimv2")
> > > Set colDiskDrives = objWMIService.ExecQuery _
> > >     ("Select * from win32_perfformatteddata_perfdisk_logicaldisk")
> > > For each objDisk in colDiskDrives
> > >     strDriveSpace = objDisk.Name & " " & objDisk.FreeMegabytes _
> > >         & VbCrLf
> > > Next
> > > strEventDescription = "File Search Completed." + vbCr + _
> > > "Please check " & Logfile & " for details." & vbCrLf & _
> > > " Number of Files Coppied: " & FileCount & vbCrLf & _
> > > objNetwork.UserDomain & "\" & objNetwork.ComputerName _
> > > & " by user " & objNetwork.UserName & _
> > > ". Free space on each drive is: " & strDriveSpace
> > > WScript.LogEvent EVENT_OK, strEventDescription

> > > Message = "File Search Completed." + vbCr + "Please check " &
Logfile
> > & _
> > > " for details." & vbCrLf
> > > Message = Message + " Number of Files Coppied: " & FileCount
> > > MsgBox Message

> > > Set objStream = Nothing
> > > Set strSearch = Nothing
> > > Set FileCount = Nothing
> > > Set BackupPath = Nothing
> > > WScript.Quit(0)
> > > ' ************************* END OF SCRIPT

***************************

- Show quoted text -

Quote:

> > > ' CheckFolder Subroutine
> > > Sub CheckFolder(objCurrentFolder, objLogFile)
> > > '    WScript.Popup Message, 1,"Entering CheckFolder"
> > >     Dim strTemp
> > >     Dim strOutput
> > >     Dim objNewFolder
> > >     Dim objFile
> > >     Dim objStream

> > >        For Each objFile In objCurrentFolder.Files
> > >            strTemp = Right(objFile.Name, 4)
> > >                 If UCase(strTemp) = UCase(strSearch) Then
> > >                     'Got one
> > >         strOutput = CStr(objFile.Name) + "," + CStr(objFile.Path)
_
> > >              + "," + CStr(objFile.Size) + "," + CStr(objFile.Type)
+
> > "," _
> > >              + CStr(objFile.datelastaccessed) + vbCrLf
> > >                    objLogFile.writeline(strOutput)
> > >                    ' Move the file to BackupPath
> > >                    FileCount = FileCount + 1
> > >                    FSO.CopyFile objFile.Name, BackupPath
> > > '                  objFile.Name.Delete
> > >                 End If
> > >        Next

> > >        'Recurse through all of the folders
> > >        For Each objNewFolder In objCurrentFolder.subFolders
> > >            If left(objNewFolder,10) = "C:\StoreTM" Or _
> > >            left(objNewFolder,10) = "C:\RECYCLE" Then
> > >                  WScript.Popup Message, 1,"Skipping C:\StoreTMP _
> > >                  or C:\RECYCLE Directory" & vbCrLf & " Processed
"_
> > >                   & FileCount & " Files."
> > >               else
> > >                 CheckFolder objNewFolder, objLogFile
> > >            end if
> > >        Next

> > > End Sub
> > > ==========================================================


> > > > Kill the error handling, you'll see a few errors.

> > > > Here are 3 things that you want to deal with to start out.

> > > > (1) Remove the Set WSH = WScript.CreateObject("WScript.Shell")
line.
> > You
> > > don't
> > > > ever use the WScript.Shell object, and WSH is a reserved word
> > anyway - you
> > > can't
> > > > make it into a variable.

> > > > (2) Change the WSH.Sleep lines to WScript.Sleep.  WScript is a
> > "built in"
> > > > object, and calling WScript.Sleep is just like calling
> > > WScript.CreateObject -
> > > > you don't need to set a variable reference to

...

read more »



Sat, 18 Dec 2004 05:50:30 GMT  
 I only learn from my mistakes
We are using W2k. WMI is not installed on the majority of computers. If
there is a better way I am all ears.  I thought that this was going to be
quick and easy . :-)

Maybe this is not what I wanted to do at all.  This whole project stems from
an across the board problem I am having with Word leaving TMP files in the
local an network drive.  The problem while I may be directing it to Drive
"C" should also include the "H: drive for each user. But I thought I would
tackle that from another script that would run on the server to handle the
network drive.

Kelly

There is nothing like jumping in feet first to find out how deep the water
is, not to mention how warm it is. ;-)



Quote:
> Kelly,

> I can see where a large chunk of your problem is coming from.  The
> primary issue here is that there is no simple mechanism for making a
> collection of files based on some criteria for an entire drive; you have
> to "build your own", so to speak.  This is a daunting task for even
> {*filter*} scripters.

> I'm looking at how this can be revised a bit - it's a problem definitely
> ripe for solving - but I wanted to ask something else.  I've noticed
> that you make use of WMI; is WMI pretty much installed on all the
> systems you are checking? And what os version are they running?  There
> may be a dramatically simpler way of doing this.

> --
> Please respond in the newsgroup.  I've still got unread email from the
> week Win95 was released, if that tells you anything.
> http://www.*-*-*.com/
> http://www.*-*-*.com/



> > Thanks for time and effort Alex.

> > Your right I am trying to:

> > 1. Find all TMP file
> > 2. Move them to a TMP directory (for later cleanup)
> > 3. Create a log file of what has been moved
> > 4. Summarize the operation, collect some information about the local
> >     computer and write it to the event log.

> > Kelly



> > > This probably should be approached somewhat differently; here's why.

> > > You set some references to the log file via FSO in your global code;
> now
> > > you're trying to access it locally.  You are probably also having
> > > problems with your mixed references to the same file which you open
> in
> > > different ways at different points.

> > > There's good news and bad news.  The good news is you really are
> making
> > > some handy use of the features of FSO.  The bad news is, it looks
> like
> > > spaghetti right now.

> > > I recall trying to work with FSO and logging the first time over a
> year
> > > ago; my code looked very much like yours does now.

> > > To get things straightened out, let's try to look at the tasks you
> want
> > > to accomplish in your code first; we will need to retrace a couple
> of
> > > steps, but you will understand what's happening much better - and
> your
> > > code will be more compact as well.

> > > From reading it, here's what I think I see you are trying to do (I'm
> not
> > > writing these in any particular order).  Could you comment on this
> > > summary of your goals?

> > > (1) You want to log the available space on each drive to the event
> log
> > > when the script is run.

> > > (2) You want to find all .TMP files not in the recycle bin (or
> already
> > > in the special directory) and move them to a special directory.

> > > (3) You want to log the names of all files moved.

> > > (4) I'm not seeing where in your code this is done, but you want to
> > > delete the files after a certain number of days.

> > > --
> > > Please respond in the newsgroup.  I've still got unread email from
> the
> > > week Win95 was released, if that tells you anything.
> > > http://www.*-*-*.com/
> > > http://www.*-*-*.com/



> > > > I am reposting the script after correcting the script.  I am
> however
> > > getting
> > > > a "C:\WSH\SearchAndLog.vbs(129, 20) Microsoft VBScript runtime
> error:
> > > Object
> > > > required: 'objLogFile'"   I have tried several thing but it is
> > > obovious I
> > > > don't understand why I am getting this error.

> > > > Thanks for your help.
> > > > Kelly
> > > > ============================================
> > > > Dim FSO
> > > > Dim ofolder
> > > > Dim objStream
> > > > Dim objLogFile
> > > > Dim strSearch
> > > > Dim FileCount
> > > > Dim BackupPath

> > > > Const EVENT_OK = 0
> > > > Const EVENT_FAILED = 2

> > > > Drive = "C:\"
> > > > LogfileDir = "C:\StoreTMP\"
> > > > strSearch = ".tmp"
> > > > BackupPath = LogfileDir
> > > > FileCount = 0
> > > > Tday = Now()
> > > > button1 = vbOKonly ' vbOKOnly

> > > > ' Parse Tday Month
> > > > If mid(Tday,2,1)="/" Then
> > > >      FileMo = Left(Tday,1)
> > > >    Else
> > > >      FileMo = Left(Tday,2)
> > > > end If
> > > > ' Parse Tday Day
> > > > If len(FileMo) = 1 And mid(Tday,4,1)="/" Then
> > > >      FileDy = Mid(tday,3,1)
> > > >    Else
> > > >      FileDy = Mid(tday,3,2)
> > > > End If

> > > > If len(FileMo) = 2 And mid(Tday,5,1)="/" Then
> > > >      FileDy = Mid(tday,4,1)
> > > >   Else
> > > >      FileDy = Mid(tday,4,2)
> > > > End If
> > > > ' Parse Tday Year
> > > > if len(FileMo) = 1 And Len(FileDy) = 1 Then
> > > >      FileYr =  Mid(tday,5,4)
> > > > End If
> > > > if len(FileMo) = 2 And Len(FileDy) = 1 Then
> > > >      FileYr =  Mid(tday,6,4)
> > > > End If
> > > > if len(FileMo) = 2 And Len(FileDy) = 2 Then
> > > >      FileYr =  Mid(tday,7,4)
> > > > End If

> > > > ' On Error Resume Next

> > > > ' Name LogFile to TMP(Date).log
> > > > Logfile = LogFileDir + "TMP" + FileMo + FileDy + FileYr + ".LOG"

> > > > Set FSO = CreateObject("scripting.filesystemobject")
> > > > ' Set objWSH = WScript.CreateObject("Wscript.Shell")

> > > > ' Check for a backup folder if no folder create it
> > > >     If not FSO.FolderExists(BackupPath) then
> > > >        FSO.CreateFolder(BackupPath)
> > > >     WScript.sleep 1000
> > > >     End If

> > > > 'Check for LogFile if not create the LogFile
> > > > ' NOTE OpenTextFile For Reading = 1, For Writing = 2, For
> Appending =
> > > 8
> > > >   If not FSO.fileExists(LogFile) Then
> > > >     Set objStream = FSO.createtextfile(Logfile, True)
> > > >     WScript.sleep 1000  ' wait 1 second - Open file for Append
> > > >     Set objLogFile = FSO.OpenTextFile(Logfile, 8, True)
> > > >        WScript.sleep 1000  ' wait 1 second
> > > >  strOutput = TDay & " **
> > > > File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " &
> > > tDay &
> > > > vbCrLf
> > > >        objLogFile.writeline (strOutput)
> > > >   Else ' Open the file for Append
> > > >     Set objLogFile = FSO.OpenTextFile(Logfile, 8, True)
> > > >        WScript.sleep 1000  ' wait 1 second
> > > >     strOutput = TDay & " **
> > > > File_Name,File_Path,File_Size,File_Type,DateLastAccessed    ** " &
> > > tDay &
> > > > vbCrLf
> > > >        objLogFile.writeline (strOutput)
> > > >   End If

> > > > ' GO SUB to CheckFolder
> > > > CheckFolder (FSO.getfolder(Drive)), objStream

> > > > ' Log Event to Windows Event Log
> > > > strComputer = "."
> > > > Set objWMIService = GetObject("winmgmts:" _
> > > >     & "{impersonationLevel=impersonate}!\\" & strComputer & _
> > > >      "\root\cimv2")
> > > > Set colDiskDrives = objWMIService.ExecQuery _
> > > >     ("Select * from win32_perfformatteddata_perfdisk_logicaldisk")
> > > > For each objDisk in colDiskDrives
> > > >     strDriveSpace = objDisk.Name & " " & objDisk.FreeMegabytes _
> > > >         & VbCrLf
> > > > Next
> > > > strEventDescription = "File Search Completed." + vbCr + _
> > > > "Please check " & Logfile & " for details." & vbCrLf & _
> > > > " Number of Files Coppied: " & FileCount & vbCrLf & _
> > > > objNetwork.UserDomain & "\" & objNetwork.ComputerName _
> > > > & " by user " & objNetwork.UserName & _
> > > > ". Free space on each drive is: " & strDriveSpace
> > > > WScript.LogEvent EVENT_OK, strEventDescription

> > > > Message = "File Search Completed." + vbCr + "Please check " &
> Logfile
> > > & _
> > > > " for details." & vbCrLf
> > > > Message = Message + " Number of Files Coppied: " & FileCount
> > > > MsgBox Message

> > > > Set objStream = Nothing
> > > > Set strSearch = Nothing
> > > > Set FileCount = Nothing
> > > > Set BackupPath = Nothing
> > > > WScript.Quit(0)
> > > > ' ************************* END OF SCRIPT
> ***************************

> > > > ' CheckFolder Subroutine
> > > > Sub CheckFolder(objCurrentFolder, objLogFile)
> > > > '    WScript.Popup Message, 1,"Entering CheckFolder"
> > > >     Dim strTemp
> > > >     Dim strOutput
> > > >     Dim objNewFolder
> > > >     Dim objFile
> > > >     Dim objStream

> > > >        For Each objFile In objCurrentFolder.Files
> > > >            strTemp = Right(objFile.Name, 4)
> > > >                 If UCase(strTemp) = UCase(strSearch) Then
> > > >                     'Got one
> > > >         strOutput = CStr(objFile.Name) + "," + CStr(objFile.Path)
> _
> > > >              + "," + CStr(objFile.Size) + "," + CStr(objFile.Type)
> +
> > > "," _
> > > >              + CStr(objFile.datelastaccessed) + vbCrLf
> > > >                    objLogFile.writeline(strOutput)
> > > >                    ' Move the file to BackupPath
> > > >                    FileCount = FileCount + 1
> > > >                    FSO.CopyFile objFile.Name, BackupPath
> > > > '                  objFile.Name.Delete
> > > >                 End If
> > > >        Next

> > > >        'Recurse through all of the folders
> > > >        For

...

read more »



Sat, 18 Dec 2004 06:07:35 GMT  
 I only learn from my mistakes
[Repost - last *3* post attempts not showing up]

Kelly,

I have mangled this beyond all recognition.

The first step is untangling the hardest part of the script: the
recursive search.
It will be much more reusable (and easier to debug) if it only does one
thing.  In this
case, I set it up as a function which searches a path for any files with
a given extension.  It does no logging, no moving, and no filtering - it
just returns an array of file paths.

Obviously we need to do some work with this when we get the array back.
However, any work is now much simpler - as is any change you make to
logging, where you store the files, etc. Here's the function and a
simple "playback" of all paths it found.

Don't worry, I'm not "abandoning" you here... :-)

Option Explicit
Dim FSO, tmpFiles, tmpFile
Set FSO = CreateObject("Scripting.FileSystemObject")
tmpFiles = FileSet("C:\",".tmp")

For each tmpFile in tmpFiles
 WScript.echo tmpFile
next

Function FileSet(FolPath, strSearch)
 ' finds all files with extension equal to strSearch
 ' in path FilPath
 '
 ' WARNING - UNCOMMENT NEXT TWO LINES IF
 ' FSO NOT DECLARED IN MAIN BODY
 ' Dim FSO
 ' Set FSO = CreateObject("Scripting.FileSystemObject")
 Dim Fil, strTemp, aFils(), oFolder, subFolder, aTmp, i
 Redim aFils(-1)
  set oFolder = FSO.GetFolder(FolPath)
 For Each Fil In oFolder.Files
  strTemp = Right(Fil.Name, 4)
  If UCase(strTemp) = UCase(strSearch) Then
  'Got one
   Redim Preserve aFils(UBound(aFils) + 1)
   aFils(UBound(aFils)) = Fil.Path
  End If
 Next
 'Recurse through all of the folders
 For Each subFolder In oFolder.subFolders
  aTmp = FileSet(subFolder, strSearch)
  For i = 0 to UBound(aTmp)
   Redim Preserve aFils(UBound(aFils) + 1)
   aFils(UBound(aFils)) = aTmp(i)
   i = i + 1
  Next
 Next
 Fileset = aFils
End Function



Mon, 20 Dec 2004 13:21:48 GMT  
 I only learn from my mistakes

Quote:

> We are using W2k. WMI is not installed on the majority of computers.

If you have Win2k, WMI is installed together with the OS (same goes for WinXP
and WinME). It is only for Win9x and NT 4.0 you must install the WMI core
yourself.

--
torgeir



Thu, 23 Dec 2004 01:08:03 GMT  
 I only learn from my mistakes
Torgeir,

So, how was Barcelona...did you pick up any new tricks <g>???

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Thu, 23 Dec 2004 01:22:02 GMT  
 
 [ 27 post ]  Go to page: [1] [2]

 Relevant Pages 

1. 5 Common Mistakes 94921039

2. Spot the mistake...

3. MS, minor Documentation mistake

4. Play sound ( mistake )

5. using PS in PDF (where is mistake?)

6. Can anyone spot the mistake

7. Type-1 font info (mistake)

8. strange mistake pls help

9. Where to learn Logon Scripting?

10. Learning Visual Basic Script

11. Learning about device control

12. best way of learning

 

 
Powered by phpBB® Forum Software