|
-
Apr 19th, 2002, 08:28 AM
#1
Thread Starter
Member
Shell - It wont close - moans about open files
This is driving me nuts. It wont close the share it opens because it says there are still open files, but I have closed any files that I open in the code.
I'm throwing this open to you folk to help me come up with things to look at. I use 'net use' to open and close the shares. I have included my main sub below which is going through each directory that I pass to it and checking for recent files. Some of the paths might be shares, so if thats the case, it opens up the share, checks the files and then closes the share (except it doesn't!)
This sub below is the only one I've changed around since it started to not work. There are other subs which lead off this one, if anyone feels the need to see those, then please let me know.
I hope someone can see something wrong (aparent from the fact that its a large sub) or suggest something.
Thanks.
Code:
Sub Detect_Recent_Files()
Dim Counter As Integer
Dim fso As FileSystemObject
Dim File As File
Dim Folder As Folder
Dim FileName
Dim FileDate
Dim StartDate As String
Dim FileNameCounter As Integer ' Used to increment filename array for each log file location
Dim Veritas_LogFiles_Count As Integer
Dim NTBackup_LogFiles_Count As Integer
Dim Robocopy_LogFiles_Count As Integer
' Local copies to redim arrays
Veritas_LogFiles_Count = 0
NTBackup_LogFiles_Count = 0
Robocopy_LogFiles_Count = 0
Counter = 0
' Global copies to increment through logfile arrays
LogFiles_Count = 0
RobocopyLogFiles_Count = 0
NTBackupLogFiles_Count = 0
StartDate = (Date - 1) & " " & Time()
For Counter = 0 To LogCounts - 1
' If the logs are on a remote share, we need to open that share and point this sub at that location
If LogInformation(Counter).LogPhysicalLocation = "SHARE" Then
' Check if there is already a share
If Dir("M:\", vbDirectory) <> "" Then
' Share which was created last time in loop has failed to close
' Indicate and report error
LogInformation(Counter).Log_Checked = False
LogInformation(Counter).Log_Checked_Reason = "Previous Log Set Share failed to be closed. Unable to report on this log set."
' Skip to end of loop
GoTo failedshare
End If
' Create a share to server where log files are
Call Create_Share(LogInformation(Counter).LogLocation)
' Indicate the drive letter that the share will be on to program, so it knows where to check for recent files
LogInformation(Counter).LogLocation = "m:\"
' Check if share was created
If Dir("M:\", vbDirectory) = "" Then
' Share drive hasn't been created
' Indicate and report error
LogInformation(Counter).Log_Checked = False
LogInformation(Counter).Log_Checked_Reason = "Failed to Create Share"
' Skip to end of loop
GoTo failedshare
End If
End If
' Reset FileNameCounter
LogInformation(Counter).LogFileNames_Counter = 0
Set fso = CreateObject("Scripting.FileSystemObject")
For Each File In fso.GetFolder(LogInformation(Counter).LogLocation).Files
' Indicate that log set was checked
LogInformation(Counter).Log_Checked = True
If (File.DateLastModified > ((Date - 1) & " " & Time())) And (File.DateLastModified < (Now())) And (File.Type = "Text Document") Then
' Check that we have found a recent file that is a veritas backup file
If LogInformation(Counter).LogType = "VERITAS" Then
' If the file type is veritas, the filename it detects as recent must start with BEX
MyName = InStr(1, File.Name, "BEX", vbTextCompare)
If MyName = 0 Then
' This recent file is not a backup file!
GoTo skipthisfile
End If
End If
' Checks for file being a NTBackup file
' Checks for file being a Robocopy file
ReDim Preserve LogInformation(Counter).LogFileNames(LogInformation(Counter).LogFileNames_Counter)
LogInformation(Counter).LogFileNames(LogInformation(Counter).LogFileNames_Counter) = LogInformation(Counter).LogLocation & "\" & File.Name
LogInformation(Counter).LogFileNames_Counter = LogInformation(Counter).LogFileNames_Counter + 1
' Prepare the logfile arrays so that they have the right number of elements ready when it comes to examing the files
If LogInformation(Counter).LogType = "VERITAS" Then
Veritas_LogFiles_Count = Veritas_LogFiles_Count + 1
ReDim Preserve LogFiles(Veritas_LogFiles_Count)
End If
If LogInformation(Counter).LogType = "NTBACKUP" Then
NTBackup_LogFiles_Count = NTBackup_LogFiles_Count + 1
ReDim Preserve NTBackupLogFiles(NTBackup_LogFiles_Count)
End If
If LogInformation(Counter).LogType = "ROBOCOPY" Then
Robocopy_LogFiles_Count = Robocopy_LogFiles_Count + 1
ReDim Preserve RobocopyLogFiles(Robocopy_LogFiles_Count)
End If
skipthisfile:
End If
Next
' Tidy up for next loop
Set fso = Nothing
Set File = Nothing
Set Folder = Nothing
' Having found a list of recent files for this particular log set we thenneed to examine them
Call Check_LogFiles(Counter)
If LogInformation(Counter).LogPhysicalLocation = "SHARE" Then
' If the files were on a remote share, disconnect that share
Call Delete_Share
End If
failedshare:
Next
' TEST BITS
For Counter = 0 To LogCounts - 1
If (LogInformation(Counter).LogFileNames_Counter) = 0 Then
' Do nothing
Else
For Counter2 = LBound(LogInformation(Counter).LogFileNames) To UBound(LogInformation(Counter).LogFileNames)
Debug.Print LogInformation(Counter).LogFileNames(Counter2)
Next
End If
Next
End Sub
"Do, or do not, there is no try".
"Never give up. Never surrender!"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|