From: Saga on
Hi all. Now I am processing data in folders. I get a listing of folder
contents and have to test to determine whether item is folder or
file. I have this routine:

strPath is previously set with valid data, strType is previously defined.

Dim objDI As New System.IO.DirectoryInfo(strPath)

For Each objFSI As System.IO.FileSystemInfo In
objDI.GetFileSystemInfos()

If objFSI.Attributes() And IO.FileAttributes.Directory Then
strType = "Folder"
Else
strType = "File"
End If

Next

My question is whether this is the best way to do this. I "explored" a bit
and
did not find any other obvious way. Any feedback is welcomed! Thanks, Saga


From: Armin Zingler on
Am 07.04.2010 21:43, schrieb Saga:
> Hi all. Now I am processing data in folders. I get a listing of folder
> contents and have to test to determine whether item is folder or
> file. I have this routine:
>
> strPath is previously set with valid data, strType is previously defined.
>
> Dim objDI As New System.IO.DirectoryInfo(strPath)
>
> For Each objFSI As System.IO.FileSystemInfo In
> objDI.GetFileSystemInfos()
>
> If objFSI.Attributes() And IO.FileAttributes.Directory Then
> strType = "Folder"
> Else
> strType = "File"
> End If
>
> Next
>
> My question is whether this is the best way to do this. I "explored" a bit
> and
> did not find any other obvious way. Any feedback is welcomed! Thanks, Saga

I'd do it your way - and switch Option Strict On.


--
Armin
From: Carl Klouda on
This method will work fine and is as good as any.

If you only need a list of files you could just do something like this:

Dim di As DirectoryInfo = New DirectoryInfo(strPath)
For Each fi As FileInfo In di.GetFiles("*.*", SearchOption.AllDirectories)
'do some work
Next

"Saga" wrote:

> Hi all. Now I am processing data in folders. I get a listing of folder
> contents and have to test to determine whether item is folder or
> file. I have this routine:
>
> strPath is previously set with valid data, strType is previously defined.
>
> Dim objDI As New System.IO.DirectoryInfo(strPath)
>
> For Each objFSI As System.IO.FileSystemInfo In
> objDI.GetFileSystemInfos()
>
> If objFSI.Attributes() And IO.FileAttributes.Directory Then
> strType = "Folder"
> Else
> strType = "File"
> End If
>
> Next
>
> My question is whether this is the best way to do this. I "explored" a bit
> and
> did not find any other obvious way. Any feedback is welcomed! Thanks, Saga
>
>
> .
>
From: Saga on
Thanks for your reply...

I have to process all files and folders, so I need a listing of both types
of items. When it is a file I check its creation date to determine if I
need to delete it. If it is a folder, I call this routine recursively to
process
that folder. Regards, Saga

"Carl Klouda" <CarlKlouda(a)discussions.microsoft.com> wrote in message
news:1A7CCA3E-125D-48B1-B0DD-30AF78466811(a)microsoft.com...
> This method will work fine and is as good as any.
>
> If you only need a list of files you could just do something like this:
>
> Dim di As DirectoryInfo = New DirectoryInfo(strPath)
> For Each fi As FileInfo In di.GetFiles("*.*", SearchOption.AllDirectories)
> 'do some work
> Next
>
> "Saga" wrote:
>
>> Hi all. Now I am processing data in folders. I get a listing of folder
>> contents and have to test to determine whether item is folder or
>> file. I have this routine:
>>
>> strPath is previously set with valid data, strType is previously defined.
>>
>> Dim objDI As New System.IO.DirectoryInfo(strPath)
>>
>> For Each objFSI As System.IO.FileSystemInfo In
>> objDI.GetFileSystemInfos()
>>
>> If objFSI.Attributes() And IO.FileAttributes.Directory Then
>> strType = "Folder"
>> Else
>> strType = "File"
>> End If
>>
>> Next
>>
>> My question is whether this is the best way to do this. I "explored" a
>> bit
>> and
>> did not find any other obvious way. Any feedback is welcomed! Thanks,
>> Saga
>>
>>
>> .
>>


From: Saga on

"Armin Zingler" <az.nospam(a)freenet.de> wrote in message
news:%23Qvb3Np1KHA.752(a)TK2MSFTNGP04.phx.gbl...

> I'd do it your way - and switch Option Strict On.
>
Thanks for the reply. Option strict ON? I have been lax with this. I
can only wonder what changes I'll have to do to the code, luckily I
just started o this project in Feb 2010, so if I am going to do this
it is best to do it now before I accumulate too many lines of code.
Thanks, Saga

>
> --
> Armin