Solved

Find a file in any subdirectory on c:\

Posted on 2004-08-09
8
207 Views
Last Modified: 2013-12-18
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
0
Comment
Question by:mcjann
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 9

Expert Comment

by:HappyFunBall
ID: 11756524
The If statement is asking if PPMTemp is the emptystring, but your first line is at least always making it "NewTemplate.dot".

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
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 11756534
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.
0
 
LVL 46

Assisted Solution

by:Sjef Bosman
Sjef Bosman earned 250 total points
ID: 11756561
See http:Q_11758718.html "Recursive routine . . . ."

0
 
LVL 9

Expert Comment

by:HappyFunBall
ID: 11756628
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.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Author Comment

by:mcjann
ID: 11756687
Yes, I do need to check all directories and subdirectories for the file.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 11757132
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.
0
 
LVL 31

Accepted Solution

by:
qwaletee earned 250 total points
ID: 11757437
You should not need to check the whole drive.  It should be enough to use the regsistry to find the folders that Word is suing, and only check those.

You are also under the misconception that the Dir function ges through all subdirectories.  It does nto.  It only checks the directory you specify, not subs.  Plus, you tacked the filename on to the end of the return result of the Dir call, when it should be part of the call itself.  Overall, I thnk you need to understand the functions better.
0
 
LVL 1

Author Comment

by:mcjann
ID: 11763157
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

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now