?
Solved

Find a file in any subdirectory on c:\

Posted on 2004-08-09
8
Medium Priority
?
231 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 1000 total points
ID: 11756561
See http:Q_11758718.html "Recursive routine . . . ."

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 
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 1000 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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
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…
When you have multiple client accounts to manage, it often feels like there aren’t enough hours in the day. With too many applications to juggle, you can’t focus on your clients, much less your growing to-do list. But that doesn’t have to be the cas…
From store locators to asset tracking and route optimization, learn how leading companies are using Google Maps APIs throughout the customer journey to increase checkout conversions, boost user engagement, and optimize order fulfillment. Powered …

569 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