Consulting

Results 1 to 5 of 5

Thread: Error after RmDir !!

  1. #1
    VBAX Newbie
    Joined
    Mar 2016
    Posts
    3
    Location

    Error after RmDir !!

    Hello,

    I am inside a folder doing the following:
    1- i am checking if a folder named "no_links" exists or not
    2- if folder "no_links" doesn't exist i am simply creating the folder
    3- if folder "no_links" exists, i am checking if it contains any files. If there are files so i delete them then i delete the folder and i try to create again the folder named "no_links" and here i get the error "Run-time error '75': path/file access error"

    I click on the end then i must go to the main folder where the folder "no_links" still showing and i must do a refresh ao the folder "no_links" disapear to be able to create it again.

    Here is my code:
    Dim strPath as String
    strPath = ThisWorkbook.Path & "\"
    
    Dim strFld as String
    strFld = strPath & "no_links\"
    
    Dim oFld as Object
    Dim oFle as Object
    
    If Dir(strFld, vbDirectory) <> "" Then
         Set oFld = CreateObject("Scripting.FileSystemObject").GetFolder(strFld)
         
         If Dir(strFld & "\*") <> "" Then
              For Each oFle in oFld.Files
                   Kill(oFle.Path)
              Next
         End If
    
         Set oFle = Nothing
         Set oFld = Nothing
    
         RmDir (strFld)
         MkDir (strFld)  'on this command line i get the error
    Else
         MkDir (strFld)
    End If
    Thank you

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Stolen from here
    Sub Test2()
        strPath = ThisWorkbook.Path & "\"
        dirstr = strPath & "no_links"
    On Error Resume Next
        If Right(dirstr, 1) <> "\" Then dirstr = dirstr & "\"
        Kill dirstr & "*.*"
        RmDir dirstr
        MkDir dirstr
    On Error GoTo 0
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Keep it simple, assume all instances met and deal with tha

    Dim strPath As String
    Dim filename As String
        strPath = ThisWorkbook.Path & "\no_links\"
        
        filename = Dir(strPath & "*.*", vbNormal)
        Do While filename <> ""
        
            Kill strPath & filename
            filename = Dir()
        Loop
        
        On Error Resume Next
        RmDir strPath
        On Error GoTo 0
         
        MkDir strPath
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Simple ?

    Sub M_snb()
        c00 = "G:\OF\no_link"
        
        With CreateObject("scripting.filesystemobject")
           If .FolderExists(c00) Then .deletefolder c00
           .CreateFolder c00
        End With
    End Sub
    But why deleting/creating a folder over and over again ?

  5. #5
    VBAX Newbie
    Joined
    Mar 2016
    Posts
    3
    Location
    Sorry for my late reply

    I will try the above mentioned methods and refer back

    Thank you everyone

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •