Looping through files in a directory

chrism84

New member
Local time
Today, 12:52
Joined
Jul 26, 2007
Messages
5
Hello,

I was wondering if someone could help me... I'm trying to loop through files within a directory, but my code doesn't seem to move past the first file. I've read that to move to a next file you could just input "myfile = dir". It doesn't seem to work here. I've pasted the code below, I'd appreciate if someone could have a look at it.

Thanks :)

Chris

Set db = CurrentDb()
myfile = Dir("C:\IN\*.*")
Do Until myfile = ""

If myfile = "" Then
MsgBox ("complete!")
Else

i = 0

fileinarr(i) = myfile
Open fileinarr(i) For Input As #1
Line Input #1, input_data
input_data = Replace(input_data, Chr(10), Chr(13))
fileout = Dir("C:\Out\" & i)
Open fileout For Output As #2
Print #2, input_data
Close #1
Close #2

DoCmd.RunSQL ("insert into filenamenew values ('" & i & "')")
i = i + 1

End If
myfile = Dir
Loop
 
Hello,

I was wondering if someone could help me... I'm trying to loop through files within a directory, but my code doesn't seem to move past the first file. I've read that to move to a next file you could just input "myfile = dir". It doesn't seem to work here. I've pasted the code below, I'd appreciate if someone could have a look at it.

Thanks :)

Chris
Code:
Set db = CurrentDb() 
[B]myfile = Dir("C:\IN\*.*")[/B]
Do Until myfile = ""

If myfile = "" Then
MsgBox ("complete!")
Else

i = 0 

fileinarr(i) = myfile
Open fileinarr(i) For Input As #1
Line Input #1, input_data
input_data = Replace(input_data, Chr(10), Chr(13))
[COLOR="Red"]fileout = Dir("C:\Out\" & i)[/COLOR]
Open fileout For Output As #2
Print #2, input_data
Close #1
Close #2

DoCmd.RunSQL ("insert into filenamenew values ('" & i & "')")
i = i + 1

End If
[B]myfile = Dir[/B]
Loop

You're resetting the dir statement. Look for the red text above.
If you use
Code:
filout = "C:\Out\" & i
this probably works better.

Enjoy!
 
Ahh excellent! Thank you very much :)
 

Users who are viewing this thread

Back
Top Bottom