Results 1 to 15 of 15
  1. #1
    kdbailey is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2012
    Posts
    228

    fso.deletefolder not working??

    I'm trying to delete a folder it ends up empty following deleting files while on a form.



    I've read all over about RmDir and fso.DeleteFolder, however both end up having the same problem for me. The folder remains afterwards, and ends up inaccessable until I either restart my computer or, through vba, recreate the folder and add new files.

    I've troubleshooted for hours now and cannot seem to figure out why it simply won't delete the folder.

    Here is the section of code that ensures there are 0 files remaining and subsequently deletes the folder. The folder remains accessible until the red line occurs, in which the folder still appears and is inaccessible. RmDir has the same effect.

    Code:
        Set fso = New FileSystemObject    Set srcfolder = fso.GetFolder("S:\Shared\Warranty Returns\WRA Data Storage\Backups\Files\Claims\" & claimnum & " " & serialno & "\")
        If srcfolder.files.count > 0 Then
            For Each fsfile In srcfolder.files
                If InStr(1, fsfile.Path, "Thumbs") = 0 Then Kill fsfile.Path
            Next
        End If
        Set fso = Nothing
        Set srcfolder = Nothing
        Set fso = CreateObject("Scripting.FileSystemObject")
        SetAttr "S:\Shared\Warranty Returns\WRA Data Storage\Backups\Files\Claims\" & claimnum & " " & serialno, vbNormal
        fso.DeleteFolder "S:\Shared\Warranty Returns\WRA Data Storage\Backups\Files\Claims\" & claimnum & " " & serialno, True
        Set fso = Nothing
    After this is run, this is the effect...

    Click image for larger version. 

Name:	Error.png 
Views:	11 
Size:	50.7 KB 
ID:	22141

  2. #2
    JamesDeckert is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    Salina, KS
    Posts
    262
    After you reboot the computer is the folder gone?
    I'm assuming the rmdir (or deletefolder) did not error?
    Ever since Vista I've seen occurrences of deleting a file or folder manually, and it would not visually delete. But if you tried again, it gave an error. It really did delete, but windows explorer wasn't updating to show it gone. I'm wonder if this might be the same problem.
    If you close and reopen explorer does that make a difference?

  3. #3
    kdbailey is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2012
    Posts
    228
    The folder does not delete when restarting windows explorer. It does delete after restarting the PC.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Try RmDir(). This is intrinsic VBA function. Don't need fso.

    But if there are permission limitations, any code could fail.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    kdbailey is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2012
    Posts
    228
    I used RmDir previously, it ended up with the same issue. It was actually the first method I was using. Permissions are not a problem at this location.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Sorry, see that now in OP.

    RmDir works for me. No idea why it fails for you.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    The next time this fails. I would run

    compmgmt.msc /computer:\\comp_name

    where comp_name is the pc that the share comes from and verify there are no open file handles to the location. Sounds more of an issue with the share than an access issue.

  8. #8
    kdbailey is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2012
    Posts
    228
    Keep in mind the code runs fine. I now believe the folder is really deleted but the explorer just doesn't represent it. It is still visible but unmanageable because it really is not there. I guess this may be more of a windows explorer error.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Interesting, I see the folder disappear immediately from Windows Explorer.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    kdbailey is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2012
    Posts
    228
    You're running 2010?

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Exactly what my profile states.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228
    I really don't know. Files delete fine, the folder does not.

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Okay, tried again. This time I put file inside the folder. Won't let me delete folder. Even crashed Access. That's using RmDir().
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    Since its a shared drive. Does the deleted folder appear deleted after remounting the shared resource?

  15. #15
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I just found this
    Code:
    Sub Delete_Whole_Folder()
    'Delete whole folder without removing the files first  
        Dim FSO As Object
        Dim MyPath As String
    
        Set FSO = CreateObject("scripting.filesystemobject")
    
        MyPath = "C:\Users\Ron\Test"  '<< Change
    
        If Right(MyPath, 1) = "\" Then
            MyPath = Left(MyPath, Len(MyPath) - 1)
        End If
    
        If FSO.FolderExists(MyPath) = False Then
            MsgBox MyPath & " doesn't exist"
            Exit Sub
        End If
    
        FSO.deletefolder MyPath
    
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 13
    Last Post: 01-22-2015, 05:27 PM
  2. Replies: 1
    Last Post: 12-27-2014, 12:38 PM
  3. Dsum was working now it is not working
    By ssalem in forum Reports
    Replies: 7
    Last Post: 04-18-2013, 02:57 PM
  4. Replies: 3
    Last Post: 01-29-2013, 04:34 AM
  5. Working with PDF's
    By Mitch87 in forum Access
    Replies: 1
    Last Post: 02-19-2010, 11:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums