473,804 Members | 2,133 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 8232
On Tue, 21 Sep 2004 20:06:38 +1000, build <bu*****@datafa st.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*****@datafa st.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(Pa d & "\" & 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*****@datafa st.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(Pa d & "\" & 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
6101
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". The form open event calls the CheckandRepairLinks without a varable being passed it it. CheckandRepairLinks
3
1666
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 window, 'nul' is returned. On the other hand, if I run Dir("c:\baat\nul"), the debug window just displays an empty line. I was wondering
32
4663
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 where the loop will be traversed a fixed number of times. It is very flexible, and novice programmers should take care not to abuse the power it offers."
5
2873
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 VS.NET 2002. When I am putting values from my SQLDataReader into labels and text boxes I am getting results such as 400.0000, or 25.90. For example... ? dr("CostsPerBin") returns
6
71984
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
2756
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 to use it in a py-file to execute command-line-style and that does not work.
3
7924
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 import shelve class XX: def __init__(self): self._data = shelve.open("/tmp/myfile")
15
2372
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 finished I want to convert the array into a string which can be used by another function. My attempt to do this is not working. The script looks like this: heights=; function getElevationInter(latv,lngv) { var script =...
9
1571
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
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10603
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10353
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10356
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10099
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9176
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5536
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.