Query on WebFiles.Delete or .Remove

C

Chris Kinata

Hi all,

Having a memory lapse I guess. I'm working on a function
that's supposed to return a list of only the .htm files in the same
folder that contains the active document.

Following is a condensed version of the function.
The var oWebFiles is a collection of all the files in the folder.
The For...Next loop checks the file extension of each file,
and if not .htm, removes it from the collection.

OK, here's the problem. As it appears here, the .Delete method
deletes not its entry in the collection, but the file itself.
Have also tried this with the Remove method with the same
result.
without deleting the file?

Thanks!

=====

Function CurrFolderFiles(sFileExt As String) As WebFiles

Dim oWebFile As WebFile
Dim oThisWebFile As WebFile
Dim oWebFolder As WebFolder
Dim oWebFiles As WebFiles
Dim sThisWebFileName As String

Set oWebFile = ActivePageWindow.File
Set oWebFolder = oWebFile.Parent
Set oWebFiles = oWebFolder.Files

For Each oThisWebFile In oWebFiles
sThisWebFileName = oThisWebFile.Name

'If the file extension <> requested extension, delete from collection.
If Right(sThisWebFileName, Len(sFileExt)) <> sFileExt Then
oWebFiles.Delete (sThisWebFileName)
Else
'do something else
End If

Next

Set CurrFolderFiles = oWebFiles

'set vars to nothing...
End Function
 
M

MD Websunlimited

You can't.

Create an array of files then load the array from the collection of webfiles. When you need to remove the file then set the array
object to nothing.

Dim oWebFiles As WebFiles
Dim oWebFile As WebFile
Dim i As Integer

Dim arrFiles() As WebFile

Set oWebFiles = ActiveWeb.RootFolder.files

ReDim arrFiles(oWebFiles.Count - 1)

For i = 0 To oWebFiles.Count - 1
Set arrFiles(i) = oWebFiles(i)
If i Mod 2 = 0 Then
Set arrFiles(i) = Nothing
End If
Next

For i = 0 To UBound(arrFiles, 1)
If Not arrFiles(i) Is Nothing Then
Debug.Print arrFiles(i).Name
Else
Debug.Print "Nothing"
End If
Next

--
Mike -- FrontPage MVP '97 - '02
http://www.websunlimited.com
FrontPage Add-ins Summer Promotion -
FREE Purchase J-Bots Plus 2004 & receive Meta Tag Maker 2004 a $24.95 value FREE
 
C

Chris Kinata

Hi Mike,

Thank you. Hmm...just seems really odd that you can't
add a layer of indirection between a reference to an
object in a collection and the object itself. Rather like
deleting the pointer to an object instead of deleting
the thing pointed to.

I was expecting (hoping?) that .Delete would delete the
object and .Remove would only take out the reference
to the object.

Regards,
Chris
 
S

Stefan B Rusynko

See
http://msdn.microsoft.com/library/d.../html/fpobjWebFiles_HV05282874.asp?frame=true

Delete is a method of WebFiles collection
Remove is a method of a Web Package that you have created

The collection represents the objects/items in it,
- so you can't change the collection (Delete/Remove) w/o affecting the collection content and its objects too (unless you create
another "information" object - per Mike's Example)

PS
- you may also want to look at the .Extension property for the WebFile object




| Hi Mike,
|
| Thank you. Hmm...just seems really odd that you can't
| add a layer of indirection between a reference to an
| object in a collection and the object itself. Rather like
| deleting the pointer to an object instead of deleting
| the thing pointed to.
|
| I was expecting (hoping?) that .Delete would delete the
| object and .Remove would only take out the reference
| to the object.
|
| Regards,
| Chris
|
| --
|||||| www.kinata.net web design and hosting
|
| | > You can't.
| >
| > Create an array of files then load the array from the collection of webfiles. When you
| > need to remove the file then set the array object to nothing.
| >
| > Dim oWebFiles As WebFiles
| > Dim oWebFile As WebFile
| > Dim i As Integer
| >
| > Dim arrFiles() As WebFile
| >
| > Set oWebFiles = ActiveWeb.RootFolder.files
| >
| > ReDim arrFiles(oWebFiles.Count - 1)
| >
| > For i = 0 To oWebFiles.Count - 1
| > Set arrFiles(i) = oWebFiles(i)
| > If i Mod 2 = 0 Then
| > Set arrFiles(i) = Nothing
| > End If
| > Next
| >
| > For i = 0 To UBound(arrFiles, 1)
| > If Not arrFiles(i) Is Nothing Then
| > Debug.Print arrFiles(i).Name
| > Else
| > Debug.Print "Nothing"
| > End If
| > Next
| >
| > --
| > Mike -- FrontPage MVP '97 - '02
| > http://www.websunlimited.com
| > FrontPage Add-ins Summer Promotion -
| > FREE Purchase J-Bots Plus 2004 & receive Meta Tag Maker 2004 a $24.95 value FREE
| >
| >
| >
| > | >> Hi all,
| >>
| >> Having a memory lapse I guess. I'm working on a function
| >> that's supposed to return a list of only the .htm files in the same
| >> folder that contains the active document.
| >>
| >> Following is a condensed version of the function.
| >> The var oWebFiles is a collection of all the files in the folder.
| >> The For...Next loop checks the file extension of each file,
| >> and if not .htm, removes it from the collection.
| >>
| >> OK, here's the problem. As it appears here, the .Delete method
| >> deletes not its entry in the collection, but the file itself.
| >> Have also tried this with the Remove method with the same
| >> result.
| >>
| >>>>Question: how would you remove an item in the collection
| >> without deleting the file?
| >>
| >> Thanks!
| >>
| >> =====
| >>
| >> Function CurrFolderFiles(sFileExt As String) As WebFiles
| >>
| >> Dim oWebFile As WebFile
| >> Dim oThisWebFile As WebFile
| >> Dim oWebFolder As WebFolder
| >> Dim oWebFiles As WebFiles
| >> Dim sThisWebFileName As String
| >>
| >> Set oWebFile = ActivePageWindow.File
| >> Set oWebFolder = oWebFile.Parent
| >> Set oWebFiles = oWebFolder.Files
| >>
| >> For Each oThisWebFile In oWebFiles
| >> sThisWebFileName = oThisWebFile.Name
| >>
| >> 'If the file extension <> requested extension, delete from collection.
| >> If Right(sThisWebFileName, Len(sFileExt)) <> sFileExt Then
| >> oWebFiles.Delete (sThisWebFileName)
| >> Else
| >> 'do something else
| >> End If
| >>
| >> Next
| >>
| >> Set CurrFolderFiles = oWebFiles
| >>
| >> 'set vars to nothing...
| >> End Function
| >>
| >>
| >>
| >
| >
|
|
 
C

Chris Kinata

Thanks guys,

The .remove I meant is a method of the collection object. When
you're coding in FPVB, it doesn't show up as belonging to the WebFile
object, but I was thinking (hoping?) that it was so generic that
it belonged to collection objects in, uh, general...

I can't find it at the MSDN site, but if you open Help in VB, it's in
the VB Reference.

Also, thanks for the .extension tip...

Regards,
Chris
 
S

Stefan B Rusynko

See
http://msdn.microsoft.com/library/d...11/html/fpmthRemove_HV01042276.asp?frame=true





| Thanks guys,
|
| The .remove I meant is a method of the collection object. When
| you're coding in FPVB, it doesn't show up as belonging to the WebFile
| object, but I was thinking (hoping?) that it was so generic that
| it belonged to collection objects in, uh, general...
|
| I can't find it at the MSDN site, but if you open Help in VB, it's in
| the VB Reference.
|
| Also, thanks for the .extension tip...
|
| Regards,
| Chris
|
| --
|||||| www.kinata.net web design and hosting
|
| | > See
| > http://msdn.microsoft.com/library/d.../html/fpobjWebFiles_HV05282874.asp?frame=true
| >
| > Delete is a method of WebFiles collection
| > Remove is a method of a Web Package that you have created
| >
| > The collection represents the objects/items in it,
| > - so you can't change the collection (Delete/Remove) w/o affecting the collection
| > content and its objects too (unless you create
| > another "information" object - per Mike's Example)
| >
| > PS
| > - you may also want to look at the .Extension property for the WebFile object
| >
| > --
| >
| > _____________________________________________
| > SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
| > "Warning - Using the F1 Key will not break anything!" (-;
| > To find the best Newsgroup for FrontPage support see:
| > http://www.net-sites.com/sitebuilder/newsgroups.asp
| > _____________________________________________
| >
| >
| > | > | Hi Mike,
| > |
| > | Thank you. Hmm...just seems really odd that you can't
| > | add a layer of indirection between a reference to an
| > | object in a collection and the object itself. Rather like
| > | deleting the pointer to an object instead of deleting
| > | the thing pointed to.
| > |
| > | I was expecting (hoping?) that .Delete would delete the
| > | object and .Remove would only take out the reference
| > | to the object.
| > |
| > | Regards,
| > | Chris
| > |
| > | --
| > |||||| www.kinata.net web design and hosting
| > |
| > | | > | > You can't.
| > | >
| > | > Create an array of files then load the array from the collection of webfiles. When
| > you
| > | > need to remove the file then set the array object to nothing.
| > | >
| > | > Dim oWebFiles As WebFiles
| > | > Dim oWebFile As WebFile
| > | > Dim i As Integer
| > | >
| > | > Dim arrFiles() As WebFile
| > | >
| > | > Set oWebFiles = ActiveWeb.RootFolder.files
| > | >
| > | > ReDim arrFiles(oWebFiles.Count - 1)
| > | >
| > | > For i = 0 To oWebFiles.Count - 1
| > | > Set arrFiles(i) = oWebFiles(i)
| > | > If i Mod 2 = 0 Then
| > | > Set arrFiles(i) = Nothing
| > | > End If
| > | > Next
| > | >
| > | > For i = 0 To UBound(arrFiles, 1)
| > | > If Not arrFiles(i) Is Nothing Then
| > | > Debug.Print arrFiles(i).Name
| > | > Else
| > | > Debug.Print "Nothing"
| > | > End If
| > | > Next
| > | >
| > | > --
| > | > Mike -- FrontPage MVP '97 - '02
| > | > http://www.websunlimited.com
| > | > FrontPage Add-ins Summer Promotion -
| > | > FREE Purchase J-Bots Plus 2004 & receive Meta Tag Maker 2004 a $24.95 value FREE
| > | >
| > | >
| > | >
| > | > | > | >> Hi all,
| > | >>
| > | >> Having a memory lapse I guess. I'm working on a function
| > | >> that's supposed to return a list of only the .htm files in the same
| > | >> folder that contains the active document.
| > | >>
| > | >> Following is a condensed version of the function.
| > | >> The var oWebFiles is a collection of all the files in the folder.
| > | >> The For...Next loop checks the file extension of each file,
| > | >> and if not .htm, removes it from the collection.
| > | >>
| > | >> OK, here's the problem. As it appears here, the .Delete method
| > | >> deletes not its entry in the collection, but the file itself.
| > | >> Have also tried this with the Remove method with the same
| > | >> result.
| > | >>
| > | >>>>Question: how would you remove an item in the collection
| > | >> without deleting the file?
| > | >>
| > | >> Thanks!
| > | >>
| > | >> =====
| > | >>
| > | >> Function CurrFolderFiles(sFileExt As String) As WebFiles
| > | >>
| > | >> Dim oWebFile As WebFile
| > | >> Dim oThisWebFile As WebFile
| > | >> Dim oWebFolder As WebFolder
| > | >> Dim oWebFiles As WebFiles
| > | >> Dim sThisWebFileName As String
| > | >>
| > | >> Set oWebFile = ActivePageWindow.File
| > | >> Set oWebFolder = oWebFile.Parent
| > | >> Set oWebFiles = oWebFolder.Files
| > | >>
| > | >> For Each oThisWebFile In oWebFiles
| > | >> sThisWebFileName = oThisWebFile.Name
| > | >>
| > | >> 'If the file extension <> requested extension, delete from collection.
| > | >> If Right(sThisWebFileName, Len(sFileExt)) <> sFileExt Then
| > | >> oWebFiles.Delete (sThisWebFileName)
| > | >> Else
| > | >> 'do something else
| > | >> End If
| > | >>
| > | >> Next
| > | >>
| > | >> Set CurrFolderFiles = oWebFiles
| > | >>
| > | >> 'set vars to nothing...
| > | >> End Function
| > | >>
| > | >>
| > | >>
| > | >
| > | >
| > |
| > |
| >
| >
|
|
 
Top