Closed Thread
Results 1 to 10 of 10

[SOLVED] Deletefolder

  1. #1
    Alvin Hansen
    Guest

    [SOLVED] Deletefolder

    HI!

    I use this:
    fso.deletefolder "c:\" & tt & tal & kur1 & "\*.*"
    its allright but if there are one folder i dosn't want to delete
    how can i do that?

    Befor the delefolder i have :

    Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1) to see if there are
    folders

    Best regards alvin



  2. #2
    Bob Phillips
    Guest

    Re: Deletefolder

    You have to iterate through all the folders

    Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1)
    For each fldr in FolderObj.SubFolders
    If fldr.name <> "special" Then
    fldr.delete
    End If
    Next fldr

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in message
    news:5E3713FB-1588-41E3-ABAD-5BC0DAC6A58A@microsoft.com...
    > HI!
    >
    > I use this:
    > fso.deletefolder "c:\" & tt & tal & kur1 & "\*.*"
    > its allright but if there are one folder i dosn't want to delete
    > how can i do that?
    >
    > Befor the delefolder i have :
    >
    > Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1) to see if there are
    > folders
    >
    > Best regards alvin
    >
    >




  3. #3
    Alvin Hansen
    Guest

    Re: Deletefolder

    Hi bob thanks
    CAn i instead of a name say if folder is readonly then
    dont delete.
    i have try with
    fso.deletefolder "c:\" & tt & tal & kur1 & "\*", False
    its working with my files but not on folders
    If the folders is emty it dele the folder if the folder have a file with
    readonly then
    i get permission denied error
    So the only thing i nead is if the folder is read only then dont delete

    regards alvin

    "Bob Phillips" skrev:

    > You have to iterate through all the folders
    >
    > Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1)
    > For each fldr in FolderObj.SubFolders
    > If fldr.name <> "special" Then
    > fldr.delete
    > End If
    > Next fldr
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in message
    > news:5E3713FB-1588-41E3-ABAD-5BC0DAC6A58A@microsoft.com...
    > > HI!
    > >
    > > I use this:
    > > fso.deletefolder "c:\" & tt & tal & kur1 & "\*.*"
    > > its allright but if there are one folder i dosn't want to delete
    > > how can i do that?
    > >
    > > Befor the delefolder i have :
    > >
    > > Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1) to see if there are
    > > folders
    > >
    > > Best regards alvin
    > >
    > >

    >
    >
    >


  4. #4
    Bob Phillips
    Guest

    Re: Deletefolder

    Like this?

    Dim fso, folderobj, fldr
    Const fsoReadonly As Long = 2

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set folderobj = fso.GetFolder("c:\myTest")
    For Each fldr In folderobj.subFolders
    If Not fldr.Attributes And fsoReadonly Then
    fldr.Delete
    End If
    Next fldr


    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in message
    news:A91D101D-6C37-4339-9CE8-A7FF2FF9EA03@microsoft.com...
    > Hi bob thanks
    > CAn i instead of a name say if folder is readonly then
    > dont delete.
    > i have try with
    > fso.deletefolder "c:\" & tt & tal & kur1 & "\*", False
    > its working with my files but not on folders
    > If the folders is emty it dele the folder if the folder have a file with
    > readonly then
    > i get permission denied error
    > So the only thing i nead is if the folder is read only then dont delete
    >
    > regards alvin
    >
    > "Bob Phillips" skrev:
    >
    > > You have to iterate through all the folders
    > >
    > > Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1)
    > > For each fldr in FolderObj.SubFolders
    > > If fldr.name <> "special" Then
    > > fldr.delete
    > > End If
    > > Next fldr
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in message
    > > news:5E3713FB-1588-41E3-ABAD-5BC0DAC6A58A@microsoft.com...
    > > > HI!
    > > >
    > > > I use this:
    > > > fso.deletefolder "c:\" & tt & tal & kur1 & "\*.*"
    > > > its allright but if there are one folder i dosn't want to delete
    > > > how can i do that?
    > > >
    > > > Befor the delefolder i have :
    > > >
    > > > Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1) to see if there

    are
    > > > folders
    > > >
    > > > Best regards alvin
    > > >
    > > >

    > >
    > >
    > >




  5. #5
    Alvin Hansen
    Guest

    Re: Deletefolder

    Thanks for the help
    Just one more please?
    If i in a folder have a file there are read only then i still get
    a permission error, its ok i not can delete the folder
    but is'n there a way to write "on error then " i have try but still i get
    this
    persmission denied

    Thanks for your help

    regards alvin


    "Bob Phillips" skrev:

    > Like this?
    >
    > Dim fso, folderobj, fldr
    > Const fsoReadonly As Long = 2
    >
    > Set fso = CreateObject("Scripting.FileSystemObject")
    > Set folderobj = fso.GetFolder("c:\myTest")
    > For Each fldr In folderobj.subFolders
    > If Not fldr.Attributes And fsoReadonly Then
    > fldr.Delete
    > End If
    > Next fldr
    >
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in message
    > news:A91D101D-6C37-4339-9CE8-A7FF2FF9EA03@microsoft.com...
    > > Hi bob thanks
    > > CAn i instead of a name say if folder is readonly then
    > > dont delete.
    > > i have try with
    > > fso.deletefolder "c:\" & tt & tal & kur1 & "\*", False
    > > its working with my files but not on folders
    > > If the folders is emty it dele the folder if the folder have a file with
    > > readonly then
    > > i get permission denied error
    > > So the only thing i nead is if the folder is read only then dont delete
    > >
    > > regards alvin
    > >
    > > "Bob Phillips" skrev:
    > >
    > > > You have to iterate through all the folders
    > > >
    > > > Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1)
    > > > For each fldr in FolderObj.SubFolders
    > > > If fldr.name <> "special" Then
    > > > fldr.delete
    > > > End If
    > > > Next fldr
    > > >
    > > > --
    > > >
    > > > HTH
    > > >
    > > > RP
    > > > (remove nothere from the email address if mailing direct)
    > > >
    > > >
    > > > "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in message
    > > > news:5E3713FB-1588-41E3-ABAD-5BC0DAC6A58A@microsoft.com...
    > > > > HI!
    > > > >
    > > > > I use this:
    > > > > fso.deletefolder "c:\" & tt & tal & kur1 & "\*.*"
    > > > > its allright but if there are one folder i dosn't want to delete
    > > > > how can i do that?
    > > > >
    > > > > Befor the delefolder i have :
    > > > >
    > > > > Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1) to see if there

    > are
    > > > > folders
    > > > >
    > > > > Best regards alvin
    > > > >
    > > > >
    > > >
    > > >
    > > >

    >
    >
    >


  6. #6
    Bob Phillips
    Guest

    Re: Deletefolder

    Have you tried?

    On Error Resume Next
    If Not fldr.Attributes And fsoReadonly Then
    fldr.Delete
    End If
    On Error Goto 0

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in message
    news:8611579B-98A3-45DB-871A-2B631510EE07@microsoft.com...
    > Thanks for the help
    > Just one more please?
    > If i in a folder have a file there are read only then i still get
    > a permission error, its ok i not can delete the folder
    > but is'n there a way to write "on error then " i have try but still i get
    > this
    > persmission denied
    >
    > Thanks for your help
    >
    > regards alvin
    >
    >
    > "Bob Phillips" skrev:
    >
    > > Like this?
    > >
    > > Dim fso, folderobj, fldr
    > > Const fsoReadonly As Long = 2
    > >
    > > Set fso = CreateObject("Scripting.FileSystemObject")
    > > Set folderobj = fso.GetFolder("c:\myTest")
    > > For Each fldr In folderobj.subFolders
    > > If Not fldr.Attributes And fsoReadonly Then
    > > fldr.Delete
    > > End If
    > > Next fldr
    > >
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in message
    > > news:A91D101D-6C37-4339-9CE8-A7FF2FF9EA03@microsoft.com...
    > > > Hi bob thanks
    > > > CAn i instead of a name say if folder is readonly then
    > > > dont delete.
    > > > i have try with
    > > > fso.deletefolder "c:\" & tt & tal & kur1 & "\*", False
    > > > its working with my files but not on folders
    > > > If the folders is emty it dele the folder if the folder have a file

    with
    > > > readonly then
    > > > i get permission denied error
    > > > So the only thing i nead is if the folder is read only then dont

    delete
    > > >
    > > > regards alvin
    > > >
    > > > "Bob Phillips" skrev:
    > > >
    > > > > You have to iterate through all the folders
    > > > >
    > > > > Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1)
    > > > > For each fldr in FolderObj.SubFolders
    > > > > If fldr.name <> "special" Then
    > > > > fldr.delete
    > > > > End If
    > > > > Next fldr
    > > > >
    > > > > --
    > > > >
    > > > > HTH
    > > > >
    > > > > RP
    > > > > (remove nothere from the email address if mailing direct)
    > > > >
    > > > >
    > > > > "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in

    message
    > > > > news:5E3713FB-1588-41E3-ABAD-5BC0DAC6A58A@microsoft.com...
    > > > > > HI!
    > > > > >
    > > > > > I use this:
    > > > > > fso.deletefolder "c:\" & tt & tal & kur1 & "\*.*"
    > > > > > its allright but if there are one folder i dosn't want to delete
    > > > > > how can i do that?
    > > > > >
    > > > > > Befor the delefolder i have :
    > > > > >
    > > > > > Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1) to see if

    there
    > > are
    > > > > > folders
    > > > > >
    > > > > > Best regards alvin
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > > >

    > >
    > >
    > >




  7. #7
    Alvin Hansen
    Guest

    Re: Deletefolder

    Well i use
    Dim fso3, folderobj, fldr
    Const fsoReadonly As Long = 2

    Set fso3 = CreateObject("Scripting.FileSystemObject")
    Set folderobj = fso3.GetFolder("c:\" & tt & tal & kur1)
    For Each fldr In folderobj.subFolders
    On Error Resume Next

    If Not fldr.Attributes And fsoReadonly Then
    fldr.Delete
    End If
    On Error GoTo 0

    Next fldr
    And still i get permission denied error, because there is a file in the
    folder there
    are read only.

    Alvin


    "Bob Phillips" skrev:

    > Have you tried?
    >
    > On Error Resume Next
    > If Not fldr.Attributes And fsoReadonly Then
    > fldr.Delete
    > End If
    > On Error Goto 0
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in message
    > news:8611579B-98A3-45DB-871A-2B631510EE07@microsoft.com...
    > > Thanks for the help
    > > Just one more please?
    > > If i in a folder have a file there are read only then i still get
    > > a permission error, its ok i not can delete the folder
    > > but is'n there a way to write "on error then " i have try but still i get
    > > this
    > > persmission denied
    > >
    > > Thanks for your help
    > >
    > > regards alvin
    > >
    > >
    > > "Bob Phillips" skrev:
    > >
    > > > Like this?
    > > >
    > > > Dim fso, folderobj, fldr
    > > > Const fsoReadonly As Long = 2
    > > >
    > > > Set fso = CreateObject("Scripting.FileSystemObject")
    > > > Set folderobj = fso.GetFolder("c:\myTest")
    > > > For Each fldr In folderobj.subFolders
    > > > If Not fldr.Attributes And fsoReadonly Then
    > > > fldr.Delete
    > > > End If
    > > > Next fldr
    > > >
    > > >
    > > > --
    > > >
    > > > HTH
    > > >
    > > > RP
    > > > (remove nothere from the email address if mailing direct)
    > > >
    > > >
    > > > "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in message
    > > > news:A91D101D-6C37-4339-9CE8-A7FF2FF9EA03@microsoft.com...
    > > > > Hi bob thanks
    > > > > CAn i instead of a name say if folder is readonly then
    > > > > dont delete.
    > > > > i have try with
    > > > > fso.deletefolder "c:\" & tt & tal & kur1 & "\*", False
    > > > > its working with my files but not on folders
    > > > > If the folders is emty it dele the folder if the folder have a file

    > with
    > > > > readonly then
    > > > > i get permission denied error
    > > > > So the only thing i nead is if the folder is read only then dont

    > delete
    > > > >
    > > > > regards alvin
    > > > >
    > > > > "Bob Phillips" skrev:
    > > > >
    > > > > > You have to iterate through all the folders
    > > > > >
    > > > > > Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1)
    > > > > > For each fldr in FolderObj.SubFolders
    > > > > > If fldr.name <> "special" Then
    > > > > > fldr.delete
    > > > > > End If
    > > > > > Next fldr
    > > > > >
    > > > > > --
    > > > > >
    > > > > > HTH
    > > > > >
    > > > > > RP
    > > > > > (remove nothere from the email address if mailing direct)
    > > > > >
    > > > > >
    > > > > > "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in

    > message
    > > > > > news:5E3713FB-1588-41E3-ABAD-5BC0DAC6A58A@microsoft.com...
    > > > > > > HI!
    > > > > > >
    > > > > > > I use this:
    > > > > > > fso.deletefolder "c:\" & tt & tal & kur1 & "\*.*"
    > > > > > > its allright but if there are one folder i dosn't want to delete
    > > > > > > how can i do that?
    > > > > > >
    > > > > > > Befor the delefolder i have :
    > > > > > >
    > > > > > > Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1) to see if

    > there
    > > > are
    > > > > > > folders
    > > > > > >
    > > > > > > Best regards alvin
    > > > > > >
    > > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > >
    > > >
    > > >

    >
    >
    >


  8. #8
    Bob Phillips
    Guest

    Re: Deletefolder

    Then you need to test each file in the folder



    For Each fldr In folderobj.subFolders
    On Error Resume Next

    If Not fldr.Attributes And fsoReadonly Then
    For Each file in fldr.Files
    If file.Attributes and fsoReadOnly Then
    'do something about it
    End If
    Next file
    fldr.Delete
    End If

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in message
    news:29696820-8574-4A38-ABC3-DFA28EE71264@microsoft.com...
    > Well i use
    > Dim fso3, folderobj, fldr
    > Const fsoReadonly As Long = 2
    >
    > Set fso3 = CreateObject("Scripting.FileSystemObject")
    > Set folderobj = fso3.GetFolder("c:\" & tt & tal & kur1)
    > For Each fldr In folderobj.subFolders
    > On Error Resume Next
    >
    > If Not fldr.Attributes And fsoReadonly Then
    > fldr.Delete
    > End If
    > On Error GoTo 0
    >
    > Next fldr
    > And still i get permission denied error, because there is a file in the
    > folder there
    > are read only.
    >
    > Alvin
    >
    >
    > "Bob Phillips" skrev:
    >
    > > Have you tried?
    > >
    > > On Error Resume Next
    > > If Not fldr.Attributes And fsoReadonly Then
    > > fldr.Delete
    > > End If
    > > On Error Goto 0
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in message
    > > news:8611579B-98A3-45DB-871A-2B631510EE07@microsoft.com...
    > > > Thanks for the help
    > > > Just one more please?
    > > > If i in a folder have a file there are read only then i still get
    > > > a permission error, its ok i not can delete the folder
    > > > but is'n there a way to write "on error then " i have try but still i

    get
    > > > this
    > > > persmission denied
    > > >
    > > > Thanks for your help
    > > >
    > > > regards alvin
    > > >
    > > >
    > > > "Bob Phillips" skrev:
    > > >
    > > > > Like this?
    > > > >
    > > > > Dim fso, folderobj, fldr
    > > > > Const fsoReadonly As Long = 2
    > > > >
    > > > > Set fso = CreateObject("Scripting.FileSystemObject")
    > > > > Set folderobj = fso.GetFolder("c:\myTest")
    > > > > For Each fldr In folderobj.subFolders
    > > > > If Not fldr.Attributes And fsoReadonly Then
    > > > > fldr.Delete
    > > > > End If
    > > > > Next fldr
    > > > >
    > > > >
    > > > > --
    > > > >
    > > > > HTH
    > > > >
    > > > > RP
    > > > > (remove nothere from the email address if mailing direct)
    > > > >
    > > > >
    > > > > "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in

    message
    > > > > news:A91D101D-6C37-4339-9CE8-A7FF2FF9EA03@microsoft.com...
    > > > > > Hi bob thanks
    > > > > > CAn i instead of a name say if folder is readonly then
    > > > > > dont delete.
    > > > > > i have try with
    > > > > > fso.deletefolder "c:\" & tt & tal & kur1 & "\*", False
    > > > > > its working with my files but not on folders
    > > > > > If the folders is emty it dele the folder if the folder have a

    file
    > > with
    > > > > > readonly then
    > > > > > i get permission denied error
    > > > > > So the only thing i nead is if the folder is read only then dont

    > > delete
    > > > > >
    > > > > > regards alvin
    > > > > >
    > > > > > "Bob Phillips" skrev:
    > > > > >
    > > > > > > You have to iterate through all the folders
    > > > > > >
    > > > > > > Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1)
    > > > > > > For each fldr in FolderObj.SubFolders
    > > > > > > If fldr.name <> "special" Then
    > > > > > > fldr.delete
    > > > > > > End If
    > > > > > > Next fldr
    > > > > > >
    > > > > > > --
    > > > > > >
    > > > > > > HTH
    > > > > > >
    > > > > > > RP
    > > > > > > (remove nothere from the email address if mailing direct)
    > > > > > >
    > > > > > >
    > > > > > > "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in

    > > message
    > > > > > > news:5E3713FB-1588-41E3-ABAD-5BC0DAC6A58A@microsoft.com...
    > > > > > > > HI!
    > > > > > > >
    > > > > > > > I use this:
    > > > > > > > fso.deletefolder "c:\" & tt & tal & kur1 & "\*.*"
    > > > > > > > its allright but if there are one folder i dosn't want to

    delete
    > > > > > > > how can i do that?
    > > > > > > >
    > > > > > > > Befor the delefolder i have :
    > > > > > > >
    > > > > > > > Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1) to see

    if
    > > there
    > > > > are
    > > > > > > > folders
    > > > > > > >
    > > > > > > > Best regards alvin
    > > > > > > >
    > > > > > > >
    > > > > > >
    > > > > > >
    > > > > > >
    > > > >
    > > > >
    > > > >

    > >
    > >
    > >




  9. #9
    Dave Peterson
    Guest

    Re: Deletefolder

    I'm not sure if it's ok to delete the folder if it's readonly or if it contains
    readonly files, but you can force those folders/files to be deleted by adding an
    option to the .delete command.

    For development, I like to set a reference to Microsoft Scripting Runtime
    (Tools|References in the VBE). Then I get a lot of help via the intellisense
    feature.

    I could do this:

    Option Explicit
    Sub testme()
    Dim FSO As Scripting.FileSystemObject
    Dim Fldr As Scripting.Folder

    Set FSO = New Scripting.FileSystemObject

    Set Fldr = FSO.GetFolder("C:\my documents\excel\test\test1")

    Fldr.Delete force:=True

    End Sub

    After I'm happy with my testing, I'll go back change those dim's to Objects and
    remove the reference.

    And for files, I'd use something like:

    Option Explicit
    Sub testme()
    Dim FSO As Scripting.FileSystemObject
    Dim Fldr As Scripting.Folder
    Dim myFile As Scripting.File

    Set FSO = New Scripting.FileSystemObject

    Set Fldr = FSO.GetFolder("C:\my documents\excel\test\test1")

    For Each myFile In Fldr.Files
    myFile.Delete force:=True
    Next myFile

    'Fldr.Delete force:=True

    End Sub

    (Or something based on this.)



    Alvin Hansen wrote:
    >
    > Hi bob thanks
    > CAn i instead of a name say if folder is readonly then
    > dont delete.
    > i have try with
    > fso.deletefolder "c:\" & tt & tal & kur1 & "\*", False
    > its working with my files but not on folders
    > If the folders is emty it dele the folder if the folder have a file with
    > readonly then
    > i get permission denied error
    > So the only thing i nead is if the folder is read only then dont delete
    >
    > regards alvin
    >
    > "Bob Phillips" skrev:
    >
    > > You have to iterate through all the folders
    > >
    > > Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1)
    > > For each fldr in FolderObj.SubFolders
    > > If fldr.name <> "special" Then
    > > fldr.delete
    > > End If
    > > Next fldr
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in message
    > > news:5E3713FB-1588-41E3-ABAD-5BC0DAC6A58A@microsoft.com...
    > > > HI!
    > > >
    > > > I use this:
    > > > fso.deletefolder "c:\" & tt & tal & kur1 & "\*.*"
    > > > its allright but if there are one folder i dosn't want to delete
    > > > how can i do that?
    > > >
    > > > Befor the delefolder i have :
    > > >
    > > > Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1) to see if there are
    > > > folders
    > > >
    > > > Best regards alvin
    > > >
    > > >

    > >
    > >
    > >


    --

    Dave Peterson

  10. #10
    Alvin Hansen
    Guest

    Re: Deletefolder

    Thanks to bob abd dave for the help

    Regards alvin


    "Dave Peterson" skrev:

    > I'm not sure if it's ok to delete the folder if it's readonly or if it contains
    > readonly files, but you can force those folders/files to be deleted by adding an
    > option to the .delete command.
    >
    > For development, I like to set a reference to Microsoft Scripting Runtime
    > (Tools|References in the VBE). Then I get a lot of help via the intellisense
    > feature.
    >
    > I could do this:
    >
    > Option Explicit
    > Sub testme()
    > Dim FSO As Scripting.FileSystemObject
    > Dim Fldr As Scripting.Folder
    >
    > Set FSO = New Scripting.FileSystemObject
    >
    > Set Fldr = FSO.GetFolder("C:\my documents\excel\test\test1")
    >
    > Fldr.Delete force:=True
    >
    > End Sub
    >
    > After I'm happy with my testing, I'll go back change those dim's to Objects and
    > remove the reference.
    >
    > And for files, I'd use something like:
    >
    > Option Explicit
    > Sub testme()
    > Dim FSO As Scripting.FileSystemObject
    > Dim Fldr As Scripting.Folder
    > Dim myFile As Scripting.File
    >
    > Set FSO = New Scripting.FileSystemObject
    >
    > Set Fldr = FSO.GetFolder("C:\my documents\excel\test\test1")
    >
    > For Each myFile In Fldr.Files
    > myFile.Delete force:=True
    > Next myFile
    >
    > 'Fldr.Delete force:=True
    >
    > End Sub
    >
    > (Or something based on this.)
    >
    >
    >
    > Alvin Hansen wrote:
    > >
    > > Hi bob thanks
    > > CAn i instead of a name say if folder is readonly then
    > > dont delete.
    > > i have try with
    > > fso.deletefolder "c:\" & tt & tal & kur1 & "\*", False
    > > its working with my files but not on folders
    > > If the folders is emty it dele the folder if the folder have a file with
    > > readonly then
    > > i get permission denied error
    > > So the only thing i nead is if the folder is read only then dont delete
    > >
    > > regards alvin
    > >
    > > "Bob Phillips" skrev:
    > >
    > > > You have to iterate through all the folders
    > > >
    > > > Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1)
    > > > For each fldr in FolderObj.SubFolders
    > > > If fldr.name <> "special" Then
    > > > fldr.delete
    > > > End If
    > > > Next fldr
    > > >
    > > > --
    > > >
    > > > HTH
    > > >
    > > > RP
    > > > (remove nothere from the email address if mailing direct)
    > > >
    > > >
    > > > "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in message
    > > > news:5E3713FB-1588-41E3-ABAD-5BC0DAC6A58A@microsoft.com...
    > > > > HI!
    > > > >
    > > > > I use this:
    > > > > fso.deletefolder "c:\" & tt & tal & kur1 & "\*.*"
    > > > > its allright but if there are one folder i dosn't want to delete
    > > > > how can i do that?
    > > > >
    > > > > Befor the delefolder i have :
    > > > >
    > > > > Set FolderObj = fso.GetFolder("c:\" & tt & tal & kur1) to see if there are
    > > > > folders
    > > > >
    > > > > Best regards alvin
    > > > >
    > > > >
    > > >
    > > >
    > > >

    >
    > --
    >
    > Dave Peterson
    >


Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1