mcjann
asked on
Find a file in any subdirectory on c:\
Hello,
I am trying to find a specific file (template.dot) anywhere on a users c:.
If the file is anywhere on the user's c: drive submit an e mail to me.
Trouble with my script is I am getting a report even when the file is not on the drive.
Any help would be great.
Sub Click(Source As Button)
PPMTemp = Dir$("C:\",16) & "NewTemplate.dot"
Print "Checking of C drive complete"
If PPMTemp <> "" Then Call SendReport
End Sub
Sub SendReport
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set doc = New NotesDocument( db )
doc.Form = "Memo"
doc.SendTo = "Jane Doe"
doc.Subject = "A copy of the template is on my C drive."
Call doc.Send( False )
End Sub
I am trying to find a specific file (template.dot) anywhere on a users c:.
If the file is anywhere on the user's c: drive submit an e mail to me.
Trouble with my script is I am getting a report even when the file is not on the drive.
Any help would be great.
Sub Click(Source As Button)
PPMTemp = Dir$("C:\",16) & "NewTemplate.dot"
Print "Checking of C drive complete"
If PPMTemp <> "" Then Call SendReport
End Sub
Sub SendReport
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set doc = New NotesDocument( db )
doc.Form = "Memo"
doc.SendTo = "Jane Doe"
doc.Subject = "A copy of the template is on my C drive."
Call doc.Send( False )
End Sub
How do you check the subdirectories? You have yo call DIr repeatedly to go through all directories, plus you have to repeat the process per subdirectory. This ain't gonna work. Let me check if there are working examples in EE.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Actually I jumped the gun there. The Dir$("C:\",16) line just looks to see if the C: drive exists. To see if a file called NewTemplate.dot exists on the C: drive, you need to use this:
PPMTemp = Dir$("C:\NewTemplate.dot", 0)
If PPMTemp <> "" Then
Print "Checking of C drive complete"
Call SendReport
End If
Or are you trying to search the entire C: drive including subdirectories? For that, you'd have to use a loop or a recursive function.
PPMTemp = Dir$("C:\NewTemplate.dot",
If PPMTemp <> "" Then
Print "Checking of C drive complete"
Call SendReport
End If
Or are you trying to search the entire C: drive including subdirectories? For that, you'd have to use a loop or a recursive function.
ASKER
Yes, I do need to check all directories and subdirectories for the file.
While you might get this problem sorted using the link I gave above, I'd like to ask why you want to know. There might be other solutions to your problem, although that may result in a too funcdamental change in the design of your application. Why do you want to know who has the template on the harddisk? To remove it afterwards?
I ask this because it might be a lot easier to save the template from a Notes template document each time than to discover the whereabouts of the file. It might take seconds, if not minutes, to walk the directory of an 80 Gb disk with a lot of info on it.
I ask this because it might be a lot easier to save the template from a Notes template document each time than to discover the whereabouts of the file. It might take seconds, if not minutes, to walk the directory of an 80 Gb disk with a lot of info on it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Investigating the link provided by sjef_bosman and motivated by qwaletee's comment. I used "Print" on both "FileFound" and "Path" to help me understand the script. This stuff is hard to learn on your own and EE has been a great resource, thank you.
I will be splitting points 50% each for the above mentioned.
My purpose is to use an e mail message to find anyone who saved the template to a local drive when they should be using the template from a controlled workgroup. These people will be targeted for retraining. I have decided to use the recursive routine with the SendReport call as follows:
Sub Click(Source As Button)
Dim PathName As String
PathName = "C:\Program Files"
Call ChkPath(pathName)
End Sub
Sub ChkPath(Path As String)
Dim Attr As Integer
Dim DirFileList List As String
Dim Count, i As Integer
Dim MemSubj As String
Dim FileFound, FileName As String
count = 0
FileName = Dir$(Path + "\*.*", 16) ' 16 = include subdirectories
' collect all relevant entries in directory
Do While FileName <> ""
If FileName <> "." And FileName <> ".." Then
DirFileList(count) = FileName
count = count + 1
End If
FileName = Dir$
Loop
' check each entry to see if it is a directory
For i = 0 To Count -1
FileFound = Path + "\" + DirFileList(i)
Attr = Getfileattr(FileFound)
If (Attr And 16) And (FileFound <> "." And FileFound <> "..") Then ' this is a directory
Call ChkPath(Cstr(FileFound)) ' recurse, but why is CStr required???
Elseif (Cstr(FileFound) =Path+"\CNC Template.dot") Then
' Print Path
Call SendReport
End If
Next
End Sub
Sub SendReport
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set doc = New NotesDocument( db )
doc.Form = "Memo"
doc.SendTo = "Jane Doe"
doc.Subject = "Template found on C drive"
Call doc.Send( False )
End Sub
I will be splitting points 50% each for the above mentioned.
My purpose is to use an e mail message to find anyone who saved the template to a local drive when they should be using the template from a controlled workgroup. These people will be targeted for retraining. I have decided to use the recursive routine with the SendReport call as follows:
Sub Click(Source As Button)
Dim PathName As String
PathName = "C:\Program Files"
Call ChkPath(pathName)
End Sub
Sub ChkPath(Path As String)
Dim Attr As Integer
Dim DirFileList List As String
Dim Count, i As Integer
Dim MemSubj As String
Dim FileFound, FileName As String
count = 0
FileName = Dir$(Path + "\*.*", 16) ' 16 = include subdirectories
' collect all relevant entries in directory
Do While FileName <> ""
If FileName <> "." And FileName <> ".." Then
DirFileList(count) = FileName
count = count + 1
End If
FileName = Dir$
Loop
' check each entry to see if it is a directory
For i = 0 To Count -1
FileFound = Path + "\" + DirFileList(i)
Attr = Getfileattr(FileFound)
If (Attr And 16) And (FileFound <> "." And FileFound <> "..") Then ' this is a directory
Call ChkPath(Cstr(FileFound)) ' recurse, but why is CStr required???
Elseif (Cstr(FileFound) =Path+"\CNC Template.dot") Then
' Print Path
Call SendReport
End If
Next
End Sub
Sub SendReport
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set doc = New NotesDocument( db )
doc.Form = "Memo"
doc.SendTo = "Jane Doe"
doc.Subject = "Template found on C drive"
Call doc.Send( False )
End Sub
Try this instead
Sub Click(Source As Button)
PPMTemp = Dir$("C:\",16)
If PPMTemp <> "" Then
PPMTemp = PPMTemp & "NewTemplate.dot"
Print "Checking of C drive complete"
Call SendReport
End If
End Sub