Page 1 of 1

Unexpected output of Dir function

Posted: Sun Apr 30, 2017 5:17 am
by stuey
Hi folx

See, I want to get some basic experience working with file I/O, so I visited this page here
https://wiki.openoffice.org/wiki/Docume ... e_Library)

which taught me the Dir function.

I have a directory "C:\stuey" with three files in it, "calcsheet", "diamond", and "asics".

I copied the function from that BASIC_Guide page I linked to above, see:

Code: Select all

Sub ShowFiles
  Dim NextFile As String
  Dim AllFiles As String
 
  AllFiles = ""
  NextFile = Dir("C:\", 0)
 
  While NextFile  <> ""
    AllFiles = AllFiles & Chr(13) &  NextFile 
    NextFile = Dir
  Wend
 
  MsgBox AllFiles
End Sub
But when I ran the code, I only got a MsgBox saying "stuey".

Shouldn't the MsgBox instead list the three files in the C:\stuey directory?

Re: Unexpected output of Dir function

Posted: Sun Apr 30, 2017 10:19 am
by RoryOF
What happens if you start with NextFile = Dir("C:\stuey", 0) or ("C:\stuey\",0)? I haven't tested which is the correct syntax.

Re: Unexpected output of Dir function

Posted: Sun Apr 30, 2017 11:52 am
by JeJe
for the initial directory try NextFile = Dir("C:\", 16) '16 for a directory

(Or RoryOf's suggestion with 16 for it)