Unexpected output of Dir function

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
stuey
Posts: 4
Joined: Sun Jan 06, 2013 10:49 am

Unexpected output of Dir function

Post 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?
OpenOffice.org 3.2.0; Ubuntu 10.04LTS
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Unexpected output of Dir function

Post 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.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Unexpected output of Dir function

Post by JeJe »

for the initial directory try NextFile = Dir("C:\", 16) '16 for a directory

(Or RoryOf's suggestion with 16 for it)
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply