Unexpected output of Dir function

Creating a macro - Writing a Script - Using the API

Unexpected output of Dir function

Postby stuey » Sun Apr 30, 2017 5:17 am

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 ... me_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   Expand viewCollapse view
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
stuey
 
Posts: 4
Joined: Sun Jan 06, 2013 10:49 am

Re: Unexpected output of Dir function

Postby RoryOF » Sun Apr 30, 2017 10:19 am

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.3 on Xubuntu 16.04 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 24934
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Unexpected output of Dir function

Postby JeJe » Sun Apr 30, 2017 11:52 am

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

(Or RoryOf's suggestion with 16 for it)
Openoffice 4.1.2
Windows 8
JeJe
 
Posts: 121
Joined: Wed Mar 09, 2016 2:40 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 6 guests