Home All Groups Group Topic Archive Search About

Dir Function just stopped working!

Author
29 Jun 2005 6:57 PM
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

Author
29 Jun 2005 7:40 PM
Armin Zingler
<bida***@yahoo.com> schrieb
Show quoteHide quote
> 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
Author
29 Jun 2005 8:00 PM
Herfried K. Wagner [MVP]
<bida***@yahoo.com> schrieb:
>        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
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>