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" wrote in message
...
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
|