Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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" wrote in message ... 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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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" wrote in message ... 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 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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" wrote in message ... 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" wrote in message ... 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 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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" 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|