Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 209
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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" 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 209
Default 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" 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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" 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 209
Default 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" 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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" 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default 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
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 209
Default 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" 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"