473,505 Members | 13,925 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dir() in Loop returns ""

G'day All,
I have a problem with this loop.
There are a number of .txt files in 'myPath'.

tmpFile = Dir(myPath & "\*.txt")
'PROCESS FOLDER
Do Until tmpFile = ""
<lottsa code>
<too much to post>
tmpFile = Dir
Loop

The first 'tmpFile = Dir(myPath & "\*.txt")'
returns the first .txt file however,
when I get to the 'tmpFile = Dir' it returns
a zero-length string ("").
Can anyone give *any* ideas what, where I should
look in the ensuing code for the problem.
I've been looking for 2 days now and am at a
total loss.

tia
build
Jul 17 '05 #1
5 8214
On Tue, 21 Sep 2004 20:06:38 +1000, build <bu*****@datafast.net.au>
wrote:
G'day All,
I have a problem with this loop.
There are a number of .txt files in 'myPath'.

tmpFile = Dir(myPath & "\*.txt")
'PROCESS FOLDER
Do Until tmpFile = ""
<lottsa code>
<too much to post>
tmpFile = Dir
Loop

The first 'tmpFile = Dir(myPath & "\*.txt")'
returns the first .txt file however,
when I get to the 'tmpFile = Dir' it returns
a zero-length string ("").
Can anyone give *any* ideas what, where I should
look in the ensuing code for the problem.
I've been looking for 2 days now and am at a
total loss.


I can make a very good guess

Somewhere in <lottsa code> you are using the Dir() function again
- that is shafting your first Dir() loop

Try reading all the .Txt file names into an Array and then processing
each item in the Array
Then dig into <lottsa code> and get rid of the culprit(s)

Dir() is a very dangerous thing to use, especially in lower
functions/subs
Jul 17 '05 #2
build wrote:
G'day All,
I have a problem with this loop.
There are a number of .txt files in 'myPath'.

tmpFile = Dir(myPath & "\*.txt")
'PROCESS FOLDER
Do Until tmpFile = ""
<lottsa code>
<too much to post>
tmpFile = Dir
Loop

The first 'tmpFile = Dir(myPath & "\*.txt")'
returns the first .txt file however,
when I get to the 'tmpFile = Dir' it returns
a zero-length string ("").
Can anyone give *any* ideas what, where I should
look in the ensuing code for the problem.
I've been looking for 2 days now and am at a
total loss.

tia
build

G'day All,
OK looks like my question is not clear enough.
What can I be doing in the code between the
'Do Until tmpFile = ""' and the 'tmpFile = Dir'
that would make the second 'Dir' return a zero
length string?
Is that clearer?
tia
build
Jul 17 '05 #3
> > I have a problem with this loop.
There are a number of .txt files in 'myPath'.

tmpFile = Dir(myPath & "\*.txt")
'PROCESS FOLDER
Do Until tmpFile = ""
<lottsa code>
<too much to post>
tmpFile = Dir
Loop

The first 'tmpFile = Dir(myPath & "\*.txt")'
returns the first .txt file however,
when I get to the 'tmpFile = Dir' it returns
a zero-length string ("").
Can anyone give *any* ideas what, where I should
look in the ensuing code for the problem.
I've been looking for 2 days now and am at a
total loss.

tia
build G'day All,
OK looks like my question is not clear enough.
What can I be doing in the code between the
'Do Until tmpFile = ""' and the 'tmpFile = Dir'
that would make the second 'Dir' return a zero
length string?


Using the Dir function with a path and filename (or without wildcards)
for a directory that has only one or no files in it. Another possibility
is a loop inside that <lottsa code> that uses Dir with a different
path/filename argument and in where the loop exhausts all the files in
that other Dir specified path/filename.
Is that clearer?


Not really.<g> Is this happening every time in the loop? Only at certain
times?

Rick - MVP

Jul 17 '05 #4
On Thu, 23 Sep 2004 07:22:23 +1000, build <bu*****@datafast.net.au>
you typed some letters in random order:
build wrote:
G'day All,
I have a problem with this loop.
There are a number of .txt files in 'myPath'.

tmpFile = Dir(myPath & "\*.txt")
'PROCESS FOLDER
Do Until tmpFile = ""
<lottsa code>
<too much to post>
tmpFile = Dir
Loop

The first 'tmpFile = Dir(myPath & "\*.txt")'
returns the first .txt file however,
when I get to the 'tmpFile = Dir' it returns
a zero-length string ("").
Can anyone give *any* ideas what, where I should
look in the ensuing code for the problem.
I've been looking for 2 days now and am at a
total loss.

tia
build

G'day All,
OK looks like my question is not clear enough.
What can I be doing in the code between the
'Do Until tmpFile = ""' and the 'tmpFile = Dir'
that would make the second 'Dir' return a zero
length string?
Is that clearer?
tia
build


I use a similar piece of code to delete old log files
Notice the start of the do/while loop it differs from yours
Perhaps that's the problem?

I just tested it again and killed 192 files with this...

<code>

Function Kill_Files(Pad As String, Datum As Date, Patroon As String)
Dim MyFile As String

MyFile = Dir(Pad & "\" & Patroon)
Do While MyFile <> ""
If FileDateTime(Pad & "\" & MyFile) < Datum Then
Kill (Pad & "\" & MyFile)
End If
MyFile = Dir ' Get next entry.
Loop
End Function

</code>


Groetjenz,

Mickey
--
#### gewoan skrieve su ast ut seist ####
Jul 17 '05 #5
mickey wrote:
On Thu, 23 Sep 2004 07:22:23 +1000, build <bu*****@datafast.net.au>
you typed some letters in random order:

build wrote:
G'day All,
I have a problem with this loop.
There are a number of .txt files in 'myPath'.

tmpFile = Dir(myPath & "\*.txt")
'PROCESS FOLDER
Do Until tmpFile = ""
<lottsa code>
<too much to post>
tmpFile = Dir
Loop

The first 'tmpFile = Dir(myPath & "\*.txt")'
returns the first .txt file however,
when I get to the 'tmpFile = Dir' it returns
a zero-length string ("").
Can anyone give *any* ideas what, where I should
look in the ensuing code for the problem.
I've been looking for 2 days now and am at a
total loss.

tia
build


G'day All,
OK looks like my question is not clear enough.
What can I be doing in the code between the
'Do Until tmpFile = ""' and the 'tmpFile = Dir'
that would make the second 'Dir' return a zero
length string?
Is that clearer?
tia
build

I use a similar piece of code to delete old log files
Notice the start of the do/while loop it differs from yours
Perhaps that's the problem?

I just tested it again and killed 192 files with this...

<code>

Function Kill_Files(Pad As String, Datum As Date, Patroon As String)
Dim MyFile As String

MyFile = Dir(Pad & "\" & Patroon)
Do While MyFile <> ""
If FileDateTime(Pad & "\" & MyFile) < Datum Then
Kill (Pad & "\" & MyFile)
End If
MyFile = Dir ' Get next entry.
Loop
End Function

</code>

Groetjenz,

Mickey


G'day Mickey,
THANK YOU for your reply.
Do While myFile "is not equal to empty string"
is the same as:
Do Until myFile "is equal to empty string"

What I've done is not an answer but avoids the problem.

Dim fileList() 'array to store filenames
Dim i as Integer 'loop counter
tmpFile = Dir(myPath & "\*.txt") 'get the first file name
Do Until tmpFile = "" ' do until empty string
ReDim Preserve fileList(i) 'set the size of array
fileList(i) = tmpFile 'put da name in array
tmpFile = Dir 'get next filename
i = i + 1 'increment counter
Loop

For i = 0 To UBound(fileList)
tmpFile = fileList(i)
<offending & offensive code>
Next i

actually it's probably clearer, easy to read etc, so better code.

Thank you again Mickey.
build
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6081
by: Ronald W. Roberts | last post by:
I'm not sure where this routine came from, but here is the problem. On certian computers this error occurs, but it does not on others. The error is: "Undefined Function "DIR" in expression". ...
3
1648
by: MLH | last post by:
Back in '98, Trevor Best posted a 1-liner I consider to be an excellent suggestion: Dir("\testdir\nul") If I have an actual directort named c:\bat and I run Dir("c:\bat\nul") in the immediate...
32
4595
by: Toby Newman | last post by:
At the page: http://www.strath.ac.uk/IT/Docs/Ccourse/subsection3_8_3.html#SECTION0008300000000000000 or http://tinyurl.com/4ptzs the author warns: "The for loop is frequently used, usually...
5
2846
by: Dan C Douglas | last post by:
I have just installed VS.NET 2003 on my computer. I have a project that I have been developing on VS.NET 2002. I haven't upgraded this project to VS.NET 2003 yet and I am still developing it in...
6
71933
by: John Pass | last post by:
What is the difference between a While and Do While/Loop repetition structure. If they is no difference (as it seems) why do both exist?
7
2742
by: per9000 | last post by:
Dear Black Knight, I have no quarrel with you sir Knight, but I must import your parents. SHORT VERSION: I tried three variants of "from ../brave.py import sir_robin", one works. I want...
3
7736
by: Michele Petrazzo | last post by:
Hi, I'm trying a script on a debian 3.1 that has problems on shelve library. The same script work well on a fedora 2 and I don't know why it create this problem on debian: #extract from my code...
15
2341
by: Steve | last post by:
I am having problems getting values out of an array. The array is set as a global array and values are pushed into it as they are read from a JSON file using a "for loop". When the "for loop" is...
9
1553
by: Alexnb | last post by:
Okay, so lets say you have a list: funList = and you do: for x in funList: print x this will print 1-5
0
7298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.