Directory Entries, Sequentially into a string..

Started by stiggity, December 23, 2010, 01:19 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

stiggity

Hello:
This is my first post to the BASIC programming sub, and i would personally like to thank Wagner, BDD, and everyone else that takes the time to reply to my posts.
what i would like to do is, open the directory channel open1,8,0,"$0:filename", and get the blocks, filename, and filetype into a string. Finding a routine like this is very hard. I have googled for days, checked the Commodore Knowledge Database, etc. If anyone can help, i would appreciate any kind of assistance. THank You.

-Stiggity

Hydrophilic

Wow, can't believe you couldn't find it.  Try this.


10 open2,8,0,"$"
20 get#2,a$:get#2,a$:rem load adrs
30 if(st and 64)thenclose2:end:rem err
40 do:get#2,a$:get#2,a$:rem line link
50 get#2,a$:x=asc(a$):get#2,a$:x=x+256*asc(a$):printx;:rem size
60 do:get#2,a$:printa$;:a=asc(a$):loopuntila=34ora=0:rem get leading space
70 ifa=0thenprint:exit:rem blocks free
80 n$="":do:get#2,a$:ifasc(a$)=34thenexit
90 n$=n$+a$:loop:rem build filename
100 printn$;a$;:rem show name+end quote
110 do:get#2,a$:ifasc(a$)=0thenexit
120 printa$;:loop:rem file type
130 print:loop
140 close2

Lines 80,90 build the filename.  On line 100 you could assign the name to an array instead of printing it on screen; maybe F$(I)=N$:I=I+1.  If you do that, note the first "filename" would really be the name of the disk and you need to DIM F$ unless you know the disk has 9 or less files.

The only problem is some directories put a quote in the filename (to escape from quote mode) so they can print special characters like CLR_SCRN.  That will ruin N$.  The only way I know to get around that is to open directory as normal file (OPEN 2,8,2,"$") but then the structure is quite different so would need a different program.
I'm kupo for kupo nuts!

stiggity

hydrophilic:
where on God's-Green-Earth did you dig that routine up?? hehehe i havnt tried it yet, but plan on in the next couple mins..
the archives on this forum? I appreciate the reply. Im writing a BBS program for the 128, and this routine is crucial.

thank you
-Steve

BigDumbDinosaur

Quote from: Hydrophilic on December 23, 2010, 03:04 AM
Wow, can't believe you couldn't find it.  Try this.


10 open2,8,0,"$"
20 get#2,a$:get#2,a$:rem load adrs
30 if(st and 64)thenclose2:end:rem err
40 do:get#2,a$:get#2,a$:rem line link
50 get#2,a$:x=asc(a$):get#2,a$:x=x+256*asc(a$):printx;:rem size
60 do:get#2,a$:printa$;:a=asc(a$):loopuntila=34ora=0:rem get leading space
70 ifa=0thenprint:exit:rem blocks free
80 n$="":do:get#2,a$:ifasc(a$)=34thenexit
90 n$=n$+a$:loop:rem build filename
100 printn$;a$;:rem show name+end quote
110 do:get#2,a$:ifasc(a$)=0thenexit
120 printa$;:loop:rem file type
130 print:loop
140 close2

Lines 80,90 build the filename.  On line 100 you could assign the name to an array instead of printing it on screen; maybe F$(I)=N$:I=I+1.  If you do that, note the first "filename" would really be the name of the disk and you need to DIM F$ unless you know the disk has 9 or less files.

The only problem is some directories put a quote in the filename (to escape from quote mode) so they can print special characters like CLR_SCRN.  That will ruin N$.  The only way I know to get around that is to open directory as normal file (OPEN 2,8,2,"$") but then the structure is quite different so would need a different program.
The other booby-trap (besides the quote one) to watch out for on the C-64 is garbage collection.  Stuffing the filenames into an array can end up running quite slowly.  It would be very instructive for you to take the above program and write it in assembly language.  It will run a lot faster and you will get some valuable experience doing I/O from disk in machine code.
x86?  We ain't got no x86.  We don't need no stinking x86!

Hydrophilic

Quote from: stiggity
where on God's-Green-Earth did you dig that routine up?? ... the archives on this forum?
...thank you
I wrote in a few minutes.  Not that I'm normally that quick, I "dug it up" mostly from memory.  Hopefully it is general and simple enough to be instructive, and easily found...
You're welcome, Merry Christmas!

@BDD:
I think stiggity is trying to work this into assembly, according some other posts he's made.  Good point about string arrays on the C64.  On the C128 it is not as bad, but can still cause problems... the C128 will freeze for *only* a dozen seconds, as opposed to a dozen minutes on C64.
I'm kupo for kupo nuts!

BigDumbDinosaur

Quote from: Hydrophilic on December 23, 2010, 01:53 PM
Quote from: stiggity
where on God's-Green-Earth did you dig that routine up?? ... the archives on this forum?
...thank you
I wrote in a few minutes.  Not that I'm normally that quick, I "dug it up" mostly from memory.  Hopefully it is general and simple enough to be instructive, and easily found...
You're welcome, Merry Christmas!

@BDD:
I think stiggity is trying to work this into assembly, according some other posts he's made.  Good point about string arrays on the C64.  On the C128 it is not as bad, but can still cause problems... the C128 will freeze for *only* a dozen seconds, as opposed to a dozen minutes on C64.
I recall long ago writing a shell sort to run in BASIC on the C-64.  The objective was modest: sort 500 names.  Thanks to garbage collection it took two days.  Fortunately there wasn't any power interruption during that time.  :)
x86?  We ain't got no x86.  We don't need no stinking x86!

stiggity

Hydro:
Thanks, coming from memory is absolutely amazing. Im the "Reference Material" dude.. ehehehhe i'd like to get a directory routine working that i have on the commodore 64 BBS, I wrote and currently run. I got bored with the 64, and since i have a 128 PRM, i figured,... "Hey, Why Not?" i started writing a bulletin board system for the 128. It's coming along, its just converting these routines i wrote for the 64, 5 years ago is sorta tuff.

BDD:
Yeah if i would have labeled my work 5 years ago, it would be less painful decyphering it now. :) You were Right! Im working on the directory routine in assem, but i dont want to print/fetch the header, or blocks free.. just a raw "123             "filename"                prg

-Steve