Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Colorado, USA
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Filesearch finding files that don't exist (Word 2003)

    I've got a Word 2003 app that counts lines of code that fist looks in a directory to find the files to count. The problem is that it seems to be remembering file names that have been deleted or renamed in the directory.

    For example, I have a file in the directory that was named code_file.for.doc that contained FORTRAN code to count. We were having problems with the tool finding the file with the Filesearch.filename property set to "*.doc". So I renamed the file to code_file_for.doc and reran the tool. It worked, suggesting the the Filesearch has a problem with miltiple dots (".") in a file name. To prove this theory to myself, I renamed the file back to the original name, code_file.for.doc, and reran the tool again. This time it complained that it couldn't find the file named "code_file_for.doc"! Stepping through the code, I found that Filesearch.FoundFiles(intI) contained "code_file_for.doc", not "code_file.for.doc" which actually exists in the directory. I even exited Word and reopened it and it still remembered the bogus file name. Here is the code snippet that is causing the errant behavior:

    ----
    'Get a list of all possible files
    With Application.FileSearch
    .NewSearch
    .LookIn = astrFileList(0)
    .SearchSubFolders = False
    .FileName = "*.doc"
    .FileType = msoFileTypeWordDocuments

    If .Execute > 0 Then
    'Check each file for the CountCode custom document property. If
    ' it has one and it is set to true add the document to the list
    ' of files to process.
    intCount = 1
    For intI = 1 To .FoundFiles.Count
    If InStr(.FoundFiles(intI), "~") = 0 And _
    InStr(LCase(.FoundFiles(intI)), "Count Code.dot") = 0 And _
    InStr(LCase(.FoundFiles(intI)), "line_count") = 0 Then
    Set objCurrDoc = Documents.Open(.FoundFiles(intI))
    ----

    Is there something I should be doing to the filesearch object once I use it to clear out the .FoundFiles array before I attempt ot load it again?


    Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Filesearch finding files that don't exist (Word 2003)

    This is very strange:
    - The NewSearch method should clear the FoundFiles array.
    - The contents of the FoundFiles array is not stored, so it shouldn't survive quitting and restarting Word.

    Make sure that you don't have a hidden instance of WINWORD.EXE in the Processes tab of Task Manager.

    Note: if you use Word as e-mail editor in Outlook, it is normal that there is a hidden instance of WINWORD.EXE as long as Outlook is active.

  3. #3
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Colorado, USA
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filesearch finding files that don't exist (Word 2003)

    Thanks, I'll check for that. I also wonder if Explorer's indexing service might be contributing to the problem. I'll check these things as report back. We're experiencing this intermitently on several machines, so we have lots of places to test it.

  4. #4
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Colorado, USA
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filesearch finding files that don't exist (Word 2003)

    After performing some checks, I discovered that no other instances of winword are running. We don't run Outlook on these systems so that was not an issue. I turned off indexing on the folder in which the file lives that contains the code that I want the tool to count and that part of the tool started to work.

    However, there is an earlier step in the process where the VB code calls a Perl script to compare two versions of the code file and generate a text file containing the code with mark-ups identifying the differences between the versions. The VB code then reads the text file into Word and does some formatting to make it look pretty. The code uses a Filesearch object to finde the collection of txt files to format, but it seems to be having a problem finding them now. Here is a code snippit that does that part of the job:

    ----
    'Process all files in the destination directory
    With Application.FileSearch
    .NewSearch
    .LookIn = strOutputLoc
    .SearchSubFolders = False
    .FileName = "*.txt"
    .FileType = msoFileTypeAllFiles

    If .Execute > 0 Then
    For intI = 1 To .FoundFiles.Count
    If InStr(.FoundFiles(intI), "~") = 0 Then
    Set objCodeFile = _
    Documents.Open(FileName:=.FoundFiles(intI), _
    ConfirmConversions:=False, _
    Format:=wdOpenFormatUnicodeText)
    Call sMarkIt(objCodeFile)
    Call sSaveFile(objCodeFile, ActiveDocument.Path)
    End If
    Next

    Else
    MsgBox "There were no files found."
    Exit Sub
    End If
    End With
    ----

    FWIW, this code was developed in Word 2000 and worked without a problem but has started to give us trouble since we migrated from Win NT to WinXP and to Office 2003. I have tried replacing the string "*.txt" with *.*, but that doesn't help either. At this point, I really don't know what to do to fix the problem.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Filesearch finding files that don't exist (Word 2003)

    If you have problems with FileSearch, you might use the good old Dir function instead.
    <code>
    Dim strPath As String
    Dim strFile As String

    strPath = strOutputLoc
    ' Make sure that path ends in a backslash
    If Not Right(strPath, 1) = "" Then
    strPath = strPath & ""
    End If

    strFile = Dir(strPath & "*.txt")
    Do While Not strFile = ""
    If InStr(strFile, "~") = 0 Then
    Set objCodeFile = Documents.Open(FileName:=strPath & strFile, _
    ConfirmConversions:=False, Format:=wdOpenFormatUnicodeText)
    Call sMarkIt(objCodeFile)
    Call sSaveFile(objCodeFile, ActiveDocument.Path)
    End If
    strFile = Dir
    Loop</code>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •