Sorry ... Missed the array and ended up putting you crook.
I'm going to have to ask you at this stage, what sort of operations are you
going to be carrying out with your FSFileSystemInf o class.
The reason I ask is that implementing your class is going to be fraught with
difficulty for reasons that include:
- FileSystemInfo is the base class for the DirectoryInfo and
FileInfo classes.
- DirectoryInfo.G etFileSystemInf os returns an array that can be
a mixture of DirectoryInfo and FileInfo objects.
- You will not be able to deal with the returned DirectoryInfo and
FileInfo objects unless you create your own classes that derive
from FSFileSystemInf o.
If you are looking to get a list of files in a directory that match a given
pattern and sort them, then you do not need to go to all this trouble.
Instead you can use the shared Directory.GetFi les(string, string) overloaded
method to return a string array of the matching files and then use one of
the shared Array.Sort overloaded methods to sort the aray, with or woithout
an IComparer as required.
"FacultasNetDev eloper" <da**********@h otmail.com> wrote in message
news:30******** *************** ***********@mic rosoft.com...
Thanks Stephany,
I tried the following and still get an error.
FSInfo = CType(DirInfo.G etFileSystemInf os("*-*.pdf"), FSFileSystemInf o())
Since FSInfo is an array I assume I will have to convert the array of
FileSystemInfo objects returned by GetFileSystemIn fos into an array of
FSFileSystemInf o Objects. However this still seems to yeild
Unable to cast object of type 'System.IO.File SystemInfo[]'
to type 'FSFileSystemIn fo[]'.
"Stephany Young" wrote:
The DirInfo.GetFile SystemInfos method is returning an object of the
FileSystemInfo type whereas you are attempting to assign it to a vaiable
of
the FSFileSystemInf o
type. You need to convert the FileSystemInfo object to a FSFileSystemInf o
object.
Try:
FSInfo = CType(DirInfo.G etFileSystemInf os("*-*.pdf"), FSFileSystemInf o)
"FacultasNetDev eloper" <da**********@h otmail.com> wrote in message
news:77******** *************** ***********@mic rosoft.com... >I am extending FileSystemInfo class so that I can Implement Icomparable.
>My
> custom class looks like:
>
> Class FSFileSystemInf o
> Inherits FileSystemInfo : Implements Icomparable
> Function CompareTo(ByVal o As Object) As Integer _
> Implements IComparable.Com pareTo
>
> My issue comes when I try to set an instance of FSFileSystemInf o to an
> object that is FileSystemInfo type. Such as:
>
> Dim DirInfo As New DirectoryInfo(" ./")
> Dim FSInfo() As FSFileSystemInf o
> DirInfo = New DirectoryInfo(S erver.MapPath(" .\"))
> FSInfo = DirInfo.GetFile SystemInfos("*-*.pdf") //THIS FAILS
>
> I get a Cast Error when I do the previous statment and I am unsure how
> to
> cast one object into another within VB.NET. Thanks for any help in
> advance.
>
>