Directory Removal

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
Once again I come to you all for help.

I simply want to delete a directory. I have read over the examples
already posted on this site and used the useful info passed on to
others but I still cannot get either "RmDir" or "FileSysObj.DeleteFolder"
to remove the directory.

I have used the RmDir command before and it worked okay, but not
in this application. I am beginning to suspect that I have crossed the
line with respect to how many levels of directories the RmDir command
can handle. In my working example I have 6 levels of directories, in
my latest example I have 7 levels of directories.

Code fragments:
Dim strDirRmv as String
Dim ojbFileSysObj as Object
 
I just wrote and tested the following code which creates 10 levels of
folders and then deletes them again:

Sub DirLevels()
Const cRoot = "C:"
Const cLevels = 10
Dim i As Integer
Dim sPath As String
sPath = cRoot
For i = 1 To cLevels
sPath = sPath & "\" & i
MkDir sPath
Next
MsgBox sPath & " created." & vbCrLf & "Click OK to remove."
Do
RmDir sPath
sPath = Left(sPath, InStrRev(sPath, "\") - 1)
Loop Until sPath = cRoot
End Sub

It works fine for me (WinXP Pro SP2 with NTFS disk). Try it on your
machine. If it works then the problem must be either in permissions, or
maybe another thread is accessing the folder you are trying to delete.

I have a vague recollection that folders on a FAT16 drive are limited to 8
levels, but if you can create them then you ought to be able to delete them.
Have you tried deleting the folder from Explorer?
 
Hi,

What made me think there was a level problem is that the code just
before the chunk I included with my original message deletes the contents
of the directory in question. And the delete part works just fine, it is when
I try to remove the directory that I get an error. Here is a chunk of the
preceeding code:

'folder exists, see if files in it
If Len(Dir(strDirRmv & "\*.*")) > 0 Then
'
'files in directory so remove them 1st
Debug.Print "H8- deleting files in folder"
Kill strDirRmv & "\*.*" ' remove all files in dir
'
End If

I am running on Windows XP Pro, but the directory and sub-directories
reside on a network drive. You were correct in your assumption about
a thread accessing the directory to be deleted. I can't even delete it
with windows explorer. Is there way to determine what thread is
causing this error?

Thanks again for your help.


Graham Mandeno said:
I just wrote and tested the following code which creates 10 levels of
folders and then deletes them again:

Sub DirLevels()
Const cRoot = "C:"
Const cLevels = 10
Dim i As Integer
Dim sPath As String
sPath = cRoot
For i = 1 To cLevels
sPath = sPath & "\" & i
MkDir sPath
Next
MsgBox sPath & " created." & vbCrLf & "Click OK to remove."
Do
RmDir sPath
sPath = Left(sPath, InStrRev(sPath, "\") - 1)
Loop Until sPath = cRoot
End Sub

It works fine for me (WinXP Pro SP2 with NTFS disk). Try it on your
machine. If it works then the problem must be either in permissions, or
maybe another thread is accessing the folder you are trying to delete.

I have a vague recollection that folders on a FAT16 drive are limited to 8
levels, but if you can create them then you ought to be able to delete them.
Have you tried deleting the folder from Explorer?
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand



CityGuy said:
Hi,
Once again I come to you all for help.

I simply want to delete a directory. I have read over the examples
already posted on this site and used the useful info passed on to
others but I still cannot get either "RmDir" or "FileSysObj.DeleteFolder"
to remove the directory.

I have used the RmDir command before and it worked okay, but not
in this application. I am beginning to suspect that I have crossed the
line with respect to how many levels of directories the RmDir command
can handle. In my working example I have 6 levels of directories, in
my latest example I have 7 levels of directories.

Code fragments:
Dim strDirRmv as String
Dim ojbFileSysObj as Object
.
.
.
'
'now remove directory
Debug.Print "H9- deleting folder"
RmDir strDirRmv ' remove dir

' i tried rmdir 1st, had no luck so then tried filesysob, still no
luck
'Set FileSysObj = CreateObject("Scripting.FileSystemObject")
'FileSysObj.DeleteFolder (strDirRmv)
'
strText01 = "Removed directory " & strKeyId
strTxtLine = "- Removed directory ...\" & strYrMonth & strDirName
.
.
.


With RmDir I get a "Path/File access error" error message.
With the FileSysObj command I get a "Permissions Denied" error message.

Can anyone shed some light as to what is failing? Thanks alot
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top