File not Found / File already open 
Author Message
 File not Found / File already open

Hi,

I'm trying to do the following in Visual Basic.
I open a file, do some processing, close the file and then try to
delete the file. (See code below)

   iFile = FreeFile
    Open sFileName For Binary Access Read As #iFile
    lFileLen = LOF(iFile)

    ....

    Close #iFile

    'DoEvents

    Kill sFileName

    'Set oSys = CreateObject("Scripting.FileSystemObject")
    'oSys.DeleteFile sFileName, True
    'Set oSys = Nothing

When I try to delete the file with the Kill statement, the following
error is raised:
Err Number: 55. Err Desc: File already open.

I've also tried deleting the file with the FileSystemObject, but I get
the following error:
Err Number: 53. Err Desc: File not found

Can anyone help?

Thanks



Sat, 26 Jun 2004 18:19:16 GMT  
 File not Found / File already open


Quote:
>I'm trying to do the following in Visual Basic.
>I open a file, do some processing, close the file and then try to
>delete the file. (See code below)

I can't reproduce this error.  What OS , VB version ?
Kill shouldn't  raise 55 though, it should raise 5 "Access denied" if
the system hasn't released the handle yet, bit unlikely.  

Does this work ?

Dim iFile as Integer
Dim lLen As Long
iFile = FreeFile
Open "c:\delme.bin" For Binary Access Read As #iFile
        lLen = Lof(iFile)
Close #iFile
Kill "C:\delme.bin"                  

What about the code between Open and Close ? Do you by any chance
overwrite sFileName or call another function passing the file handle ?

Quote:
>    'Set oSys = CreateObject("Scripting.FileSystemObject")
>    'oSys.DeleteFile sFileName, True
>    'Set oSys = Nothing

Eh, don't bother with the FSO.

Regards, Frank



Sun, 27 Jun 2004 05:44:52 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Opening a dBase file : file not found but it exists really

2. How to open a file for read that is already open by another application

3. ShellExecute only opens file.htm if browser already open

4. Open an already opened file

5. Help File - Opens on Find tab not Contents tab

6. how do i find if a file already exists

7. checking if a file is already open

8. Word cannot save this file because it is already open elsewhere

9. Reading/deleting in a shared textfile (error 55: File already open)

10. Determine if file is already open

11. Check if a file is already open.

12. Open File to detect if associated app already running

 

 
Powered by phpBB® Forum Software