Link to home
Start Free TrialLog in
Avatar of dcobau
dcobau

asked on

Delete a directory - Access 97

Hi all,

1 of my procedures creates a temp directory (c:\TempImportDb) in which I put a copy of empty tables, import some data, and do some stuff. At the end I want to delete the temp database (kill statement which works fine) and then delete the temp directory (RmDir which does not work at all). I do:

     Dim dbPathDir As String
     dbPathDir = "C:\TempImportDb\"

     If fIsFileDIR("C:\TempImportDb\", vbDirectory) = True Then
              RmDir dbPathDir
     End If

I am getting error 75, "Path/File access error". Seems like access thinks that the file is still being used. I also tried the ChDir command befor the RmDir but no joy. Any ideas?

Any advice would be appreciated

Dave
Avatar of gbaren
gbaren
Flag of United States of America image

Try ChDir to another directory before deleting it.
Avatar of cjswimmer
cjswimmer

If there are any files left in the directory, the kill statement will fail.  If you are opening an Access db file in that dir, it creates an ldb file while it is open.  The ldb file might not be deleted by the time you try to kill the dir.  Try testing for dir(C:\TempImportDb\*.*) in a loop and use a Kill function for everything it finds until the Dir returns "".  You might want to trap for errors too in case Access is still closing and you can't delete the ldb file.  hope this helps.

cjswimmer
Add a reference to Microsoft Scripting Runtime library and delete using the FileSystemObject. You can also use the FileSystemObject to move or delete files.  I use it with Access 2000,  Don't think it works with 97 though.

Jack

For example

Sub TempFolder()
Dim objFS As New Scripting.FileSystemObject
Dim strFolder As String

strFolder = "C:\TempImportDb\"

If objFS.FolderExists(strFolder) Then
  objFS.DeleteFolder (strFolder)
   MsgBox "Folder " & strFolder & " deleted"
   Else
   MsgBox "Folder " & strFolder & " does not exist"
 End If


Set objFS = Nothing
End Sub
According to  'VB and VBA in a Nutshell' this FileSystemObject.DeleteFolder method will delete folders and contents (files and subdirectories). (Permanent delete not recycle bin)  Can set option to force it to delete read only files if needed.
Jack
Avatar of dcobau

ASKER

Well, thanks everybody for your comments. I have resolved my problem by deleting the directory (if it exhist)from another db. db1 opens db2 where I create the temp dir and where I wanted to delete it after doing things. Now I check and delete it from db1 before opening db2.

Thanks again

Dave
If the problem is resolved then you need to either delete the question if you discovered the solution completely on your own or award the points to one of the experts.  Did any of the posts in this thread contribute to your solution?  
Avatar of dcobau

ASKER

hi ciswimmer,

I worked out a solution by myself, so I guess I need to delete the question. How do I do that?

Dave
It looks like you've got 6 other questions that are in some sort of limbo from the past year or so.  You should revisit those questions and either delete them if the problem was never solved, continue the discussion, or award the points to the closest solution.  Experts who examine a question owner's profile may be less likely to participate in offering a solution if they see that you do not follow through on finishing the session.  Just a suggestion.

cjswimmer
ASKER CERTIFIED SOLUTION
Avatar of ComTech
ComTech

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial