Listing files held a sub-directory
 
 
 
PST User Forum
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



Listing files held a sub-directory Expand / Collapse
Author
Message
Posted 6/26/2008 6:50:18 AM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 11/24/2008 9:53:16 AM
Posts: 20, Visits: 85
Hi,

I'm trying to create a list of files that are held in a sub-folder.

The two examples below should (in my opinion!) give the same result. ie; list the first two files held in "SubFolder01".

But... only Example 1 works. Example 2 just adds the word "files", then two blank lines, in the debug window.

I'd rather not have to change directory just to read what's there, so can someone please tell me what's wrong with my code?

Thanks, J.

EPrime v2.0

'=========================== Example 1     

ChDir ("SubFolder01")

dim i%
Dim a$(10)

a(1) = Dir$("*.*")
i = 1
While (a(i) <> "") And (i < 10)
 i = i + 1
 a(i) = Dir$()
Wend

debug.print "files: " & crlf & a(1) & crlf & a(2)


'=========================== Example 2

dim i%
Dim a$(10)

a(1) = Dir$("SubFolder01\*.*")
i = 1
While (a(i) <> "") And (i < 10)
 i = i + 1
 a(i) = Dir$()
Wend

debug.print "files: " & crlf & a(1) & crlf & a(2)

'===========================

...I'm an immortal...so far...

Post #1718
Posted 6/26/2008 6:59:42 AM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 11/24/2008 9:53:16 AM
Posts: 20, Visits: 85
Sorry! I meant to say I'm using E-Prime version 1.0,  NOT version 2!  ... I can't work out how to edit my original post...

J

...I'm an immortal...so far...

Post #1719
Posted 6/27/2008 12:54:14 PM
Forum MVP

Forum MVPForum MVPForum MVPForum MVPForum MVPForum MVPForum MVPForum MVP

Group: Forum Members
Last Login: Today @ 5:01:25 PM
Posts: 336, Visits: 897
JackOByte,

Just a guess, since I did not bother to test this myself...

Since E-Prime has the CStrings option on, the backslash '\' character acts as an "escape" character. Thus, the line

a(1) = Dir$("SubFolder01\*.*")

Gets interpreted as

a(1) = Dir$("SubFolder01.*")

To avoid this, you need to escape the escape, e.g.,

a(1) = Dir$("SubFolder01\\*.*")

Alternatively, in E-Prime (and in fact in most places in modern Windows) you can use a forward slash in place of a backslash for a path separator, e.g.,

a(1) = Dir$("SubFolder01/*.*")

And that is my preferred practice.

Hope this helps,
-- David McFarlane, Professional Faultfinder
Post #1724
Posted 7/8/2008 5:13:03 AM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 11/24/2008 9:53:16 AM
Posts: 20, Visits: 85
Morning Dave,

Mmm, that never even crossed my mind! I gave it a go and...

a(1) = Dir$("SubFolder01\\*.*")    works,  but    a(1) = Dir$("SubFolder01/*.*")    doesn't.

Much thanks,

J

...I'm an immortal...so far...

Post #1761
« Prev Topic | Next Topic »


Permissions Expand / Collapse

All times are GMT -5:00, Time now is 10:43pm

Powered By InstantForum.NET v4.1.4 © 2009
Execution: 0.125. 11 queries. Compression Disabled.