Dir Function just stopped working!

B

bidalah

Hi,

Following is a simple version of my now non-working code:

hihi = Dir("c:\burn2\*.*", FileAttribute.Normal)
Do While Len(hihi) > 0
hoho = hehe
hihi = Dir()
Loop

All I am looking to do is perform certain functions on each file in a
directory ("burn2"). This has been working for months. Today I made
some unrelated changes to the the program, and now, when I try to run
the program, the Dir function only works the first time. When it trys
to access the 2nd file, it doesn't find anything, and so goes out of
the loop.

I tried taking the changes out. I've tried sticking the exact code you
see above into my program just to see the dir() function work properly.
It doesn't. I've tried creating a new solution and project with JUST
THE ABOVE CODE, nothing more. Dir() still only works the first time.

Closing out vb.net and rebooting my computer doesn't help either. At
this point, either I am missing something simple, or I feel I need to
reinstall vb.net. Any ideas?

Thank you in advance for any help!
Mike Cooper
 
A

Armin Zingler

Hi,

Following is a simple version of my now non-working code:

hihi = Dir("c:\burn2\*.*", FileAttribute.Normal)
Do While Len(hihi) > 0
hoho = hehe
hihi = Dir()
Loop

All I am looking to do is perform certain functions on each file in
a directory ("burn2"). This has been working for months. Today I
made some unrelated changes to the the program, and now, when I try
to run the program, the Dir function only works the first time.
When it trys to access the 2nd file, it doesn't find anything, and
so goes out of the loop.

I tried taking the changes out. I've tried sticking the exact code
you see above into my program just to see the dir() function work
properly. It doesn't. I've tried creating a new solution and
project with JUST THE ABOVE CODE, nothing more. Dir() still only
works the first time.

Closing out vb.net and rebooting my computer doesn't help either. At
this point, either I am missing something simple, or I feel I need
to reinstall vb.net. Any ideas?

Thank you in advance for any help!
Mike Cooper

No solution, but why not use the System.IO classes? Even if you wanna stay
with Dir(), try it this time with

dim files as string()
fils = System.IO.Directory.GetFiles("c:\burn2", "*,*")

What does files contain afterwards?

Armin
 
H

Herfried K. Wagner [MVP]

hihi = Dir("c:\burn2\*.*", FileAttribute.Normal)
Do While Len(hihi) > 0
hoho = hehe
hihi = Dir()
Loop

All I am looking to do is perform certain functions on each file in a
directory ("burn2"). This has been working for months. Today I made
some unrelated changes to the the program, and now, when I try to run
the program, the Dir function only works the first time. When it trys
to access the 2nd file, it doesn't find anything, and so goes out of
the loop.

I suggest not to use 'Dir' for file enumeration because it is not
re-entrant. You can use 'System.IO.Directory.GetFiles' instead:

\\\
Imports System.IO
..
..
..
For Each FileName As String In Directory.GetFiles("C:\foo", "*.*")
...
Next FileName
///
 

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