|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Sharing violation when trying to delete a file.(ftpclien_online.txt) when it is running, and then deletes that flag file when it is finished. I then have another VB5 program (mvmctrl.exe) which looks for that flag file with the following code: If Dir(DirToDo + "FTPClien_ONLINE.TXT") <> "" Then LogDebug "Didn't do CreateArray - FTPClien_ONLINE.TXT exists", "High" BadFTPClient = BadFTPClient + 1 ' increment counter - may have a problem! Exit Sub Else BadFTPClient = 0 ' reset it. txtStatus.BackColor = vbWhite End If As you can see, it doesn't even open the flag file - just tests whether it exists or not.If it exists, mvmctrl.exe does nothing for this cycle and waits 30 seconds for the next cycle. On 1 machine I have intermittent problems where for some reason the mvmctrl.exe application locks the file, so when the ftpclien.exe application tries to delete it, it can't - gets an error 70 sharing violation. And then of course the mvmctrl.exe application on it's next cycle thinks that ftpclien.exe is still running, so it refuses to do any processing. Previously I could quit mvmctrl.exe & ftpclien.exe would then be able to delete the flag file at the end of it's run, then restart mvmctrl.exe & all would be ok for another day or 2. Then I started looking into it further & found 2 utility applications - unlocker.exe and wholockme.exe, which both confirm that the flag file can't be removed because it is locked by mvmctrl.exe & these 2 utilities will even allow me to unlock the file without having to stop my mvmctrl.exe application. However, I want to solve the problem rather than work around it. Can anyone tell me why the simple act of doing a dir() on a file would lock it so that other applications can't delete it? And any way to stop it doing so? One other point - I am using Windows 2000, and a few newsgroup threads have hinted that this might actually be a win2k problem, and certainly I haven't noticed it on my other Win XP machine. It must be possible to release the lock under program control though, as both unlocker.exe & wholockme.exe manage to do it cleanly. Thanks, Dave
Show quote
Hide quote
"Dave Baker" <newsgroup_pos***@jodael.com> wrote in message Instead of using the Dir function to check existance, use something like news:ucdvk1l31regln0a6bmepukp5439ptbp9n@4ax.com... >I have a VB5 application (ftpclien.exe) which creates a flag file > (ftpclien_online.txt) when it is running, and then deletes that flag file > when it is finished. > > I then have another VB5 program (mvmctrl.exe) which looks for that flag > file > with the following code: > > If Dir(DirToDo + "FTPClien_ONLINE.TXT") <> "" Then > LogDebug "Didn't do CreateArray - FTPClien_ONLINE.TXT exists", "High" > BadFTPClient = BadFTPClient + 1 ' increment counter - may have a > problem! > Exit Sub > Else > BadFTPClient = 0 ' reset it. > txtStatus.BackColor = vbWhite > End If > > As you can see, it doesn't even open the flag file - just tests whether it > exists or not.If it exists, mvmctrl.exe does nothing for this cycle and > waits > 30 seconds for the next cycle. below (air code). It's possible that Dir is putting some kind of lock on the file. Besides that, using Dir to check for a file's existance can cause problems with other uses of Dir. Public Function FileExists(ByVal FileName As String) As Boolean On Error GoTo EH If (GetAttr(FileName) And vbDirectory) <> vbDirectory Then FileExists = True End If Exit Function EH: FileExists = False End Function Oh.....and NEVER use + for string concatenation. Use the & operator. -- Mike Microsoft MVP Visual Basic On Fri, 14 Oct 2005 11:33:43 -0400, "MikeD" <nob***@nowhere.edu> <snip>wrote: >Instead of using the Dir function to check existance, use something like Or :->below (air code). It's possible that Dir is putting some kind of lock on >the file. Besides that, using Dir to check for a file's existance can cause >problems with other uses of Dir. Public Function FileExists(ByVal FileName As String) As Boolean On Error Resume Next If (GetAttr(FileName) And vbDirectory) <> vbDirectory Then If Err = 0 Then FileExists = True End If End If End Function |
|||||||||||||||||||||||