RE: Error 52 Bad file or file number

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Darwin Abustan[MSFT] (darwina_at_online.microsoft.com)
Date: 11/23/04


Date: Tue, 23 Nov 2004 03:44:32 GMT


--------------------
>I have some code that will traverse through a folder/file structure and then create a similar representation of the structure as HTML. I open a file for output
(inc_CNILibrary.html) then traverse the tree and write to the file every time I encounter a folder or file. The LoadShareFolderTree function is recursive and calls itself
everytime a new folder is found. For no rhyme or reason, sometimes the code executes without a problem, other times it fails at different points in the traversal with the err52
message. Sometimes it fails after only a few lines have been written to the output file; other times after dozens of lines; other times it does not fail at all. Anyone have an
idea what could be causing the output file to get closed prematurely or VB to loose it's connection to the file handle?

    fno = FreeFile

    fname = App.Path & "\temp\" & pFName

    Open fname For Output As #fno

    

    'add the root folder

    Set fld = fso.GetFolder(pPath)

    Print #fno, "<p>"

    For Each tFld In fld.SubFolders

        Print #fno, tFld.Name & "<br>"

    Next

    If fld.SubFolders.Count > 0 Then

        For Each tFld In fld.SubFolders

            Call LoadShareFolderTree(tFld, intThisFolder, fno)

        Next

    End If

    Print #fno, "Last Updated: " & Format(Now, "MM/DD/YY HH:NN")

    Close #fno

Private Sub LoadShareFolderTree(prmFld As Folder, ByVal prmIndex As Integer, ByVal fno As Long)

...

Print #fno, SpacerWeb(prmIndex) & "<img src=images/folder.gif>&nbsp;" & prmFld.Name & "<br>"
>

Cannot deduce why this is happening with the code samples provided.

The following article provides an example of a scenario where you would receive Error '52'

PRB: Cannot Simultaneously Write to Disk File and Have It Opened in ActiveX DLL
http://support.microsoft.com/kb/q214674/

Darwin Abustan
Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.



Relevant Pages

  • Re: Traverse Folder
    ... Traverse a folder does not mean List the content of the folder's ... to the lower level folder starting at the top if they cannot list ... with permissions at Level4 attempts a direct access to that ...
    (microsoft.public.windows.server.security)
  • Re: Count of messages in a pst
    ... > Is there code examples on how to traverse the IMAPITable hierarchy? ... >> faster than opening each folder and getting a table on it. ... >>> If i'm loading a PST outlook data file and i want to know how many ...
    (microsoft.public.win32.programmer.messaging)
  • Sharing & NTFS Permissions
    ... If there is anyone out there who is proficient with Windows shares and NTFS ... This is regarding the Traverse ... Folder permission. ... Everyone group the Traverse Folder permission at C:\Test. ...
    (microsoft.public.win2000.security)
  • Sharing & NTFS Permissions
    ... If there is anyone out there who is proficient with Windows shares and NTFS ... This is regarding the Traverse ... Folder permission. ... Everyone group the Traverse Folder permission at C:\Test. ...
    (microsoft.public.security)
  • Re: directory structure xsl transformation question
    ... I have modified the xsl above that formats the xml to folder/file structure ... to now output html in a table, row format. ...
    (microsoft.public.dotnet.xml)