[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Find a file in any subdirectory on c:\

Posted on 2004-08-09
8
Medium Priority
?
230 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
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
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

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

591 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