FileIO.SearchOption.SearchTopLevelOnly - Broken?

  • Thread starter Thread starter roidy
  • Start date Start date
R

roidy

I`ve go the following code to return all the .txt files in a directory but
NOT in any sub-directories:-

For Each str As String In My.Computer.FileSystem.GetFiles("c:\Folder", _
FileIO.SearchOption.SearchTopLevelOnly,
_
"*.txt")

....... Do some stuff with the files


Next

However even with FileIO.SearchOption.SearchTopLevelOnly set it still
returns files that are in sub-directories, any idea why?

Rob
 
However even with FileIO.SearchOption.SearchTopLevelOnly set it still
returns files that are in sub-directories, any idea why?

Very strange. I have Windows Vista with .NET Framework 3.5 and it works as
it should. I can't reproduce your problem with my computer.

-Teemu
 
roidy said:
I`ve go the following code to return all the .txt files in a directory but
NOT in any sub-directories:-

For Each str As String In My.Computer.FileSystem.GetFiles("c:\Folder", _
FileIO.SearchOption.SearchTopLevelOnly,
_
"*.txt")

...... Do some stuff with the files


Next

However even with FileIO.SearchOption.SearchTopLevelOnly set it still
returns files that are in sub-directories, any idea why?

I don't know, but have you already tried the straight way? See
System.IO.Directory.GetFiles
http://msdn.microsoft.com/en-us/library/ms143316.aspx


Armin
 
Teemu said:
Very strange. I have Windows Vista with .NET Framework 3.5 and it works as
it should. I can't reproduce your problem with my computer.

You must try His.Computer. ;)


Armin
 
Woops! I`m an idiot, I was using an old version of the function I`m writing
with FileIO.SearchOption.SearchTopLevelOnly omitted and I forgot to update
my program to use the new version. Sorry, I`ll go stand in the corner now
and bang my head against the wall :)
 
Yep that's what happens when you sit staring at the code for too
long......... It all starts to blur together
 
Yep I posted a while ago about System.IO.Directory.GetFiles. Its ok but
doesn't allow multilpe wildcards, which I need sometimes, so its easier just
to use My.Computer.

And I know some people seem to hate My.Computer with a passion but I don't
mine it as long as it works :)

Rob
 
Back
Top