FileIO.SearchOption.SearchTopLevelOnly - Broken?

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
 
T

Teemu

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
 
A

Armin Zingler

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
 
A

Armin Zingler

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
 
R

roidy

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 :)
 
R

roidy

Yep that's what happens when you sit staring at the code for too
long......... It all starts to blur together
 
R

roidy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top