Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Directory Removal

Discussion in 'Information Technology' started by CityGuy, Jul 28, 2006.

  1. CityGuy

    CityGuy
    Expand Collapse
    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
     
  2. Loading...

    Similar Threads Forum Date
    Sikhs in England (Business Directory) Business, Lifestyle & Leisure Aug 22, 2008
    Gurdwara Directory for Australia and New Zealand New to Sikhism Jul 15, 2007
    Gurdwara Directory United Kingdom and Europe New to Gurdwara Jul 14, 2007
    Gurdwara Directory South and Central America New to Gurdwara Jul 14, 2007
    Gurdwara Directory for the United States and Canada New to Gurdwara Jul 13, 2007

  3. Graham Mandeno

    Graham Mandeno
    Expand Collapse
    Guest

    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" <CityGuy@discussions.microsoft.com> wrote in message
    news:04AB66D2-4666-49D3-9C05-B5DD6B4FCADF@microsoft.com...
    > 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
     
  4. CityGuy

    CityGuy
    Expand Collapse
    Guest

    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" wrote:

    > 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" <CityGuy@discussions.microsoft.com> wrote in message
    > news:04AB66D2-4666-49D3-9C05-B5DD6B4FCADF@microsoft.com...
    > > 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

    >
    >
    >
     

Share This Page