Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Find a file in any subdirectory on c:\

Posted on 2004-08-09
8
Medium Priority
?
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

715 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