File size, file seek, type a file
giannissam
Posts: 22
Hi all,
3 questions:
1.Can someone tell me if it is possible to read the size of a file without having to read the whole file byte by byte?
(using some of the sd objects)
2. Is it possible to seek a position in a file?
for example say a routine named seek(filename,position) whose job is to seek in a file (filename) the position requested.
for example i have the text file Hello.txt with contents "Hello people". if i run seek("hello.txt",3) the pointer goes to the 1st or 2nd "l" (depending on starting counting by 0 or 1)
i know i can do it by reading some characters (equal to position) but if i want to run this routine many times i will have to read the characters lots of times... its gonna be time consuming...
3. I have a problem on typing a file on screen.
I read character by character and print it on screen.
it works great if the thext is sequential. If for example i copy the text from this post and paste it in a file and run the type code, i get all type of characters on screen. i guess it has something to do with changing the line. How can i correct that?
3 questions:
1.Can someone tell me if it is possible to read the size of a file without having to read the whole file byte by byte?
(using some of the sd objects)
2. Is it possible to seek a position in a file?
for example say a routine named seek(filename,position) whose job is to seek in a file (filename) the position requested.
for example i have the text file Hello.txt with contents "Hello people". if i run seek("hello.txt",3) the pointer goes to the 1st or 2nd "l" (depending on starting counting by 0 or 1)
i know i can do it by reading some characters (equal to position) but if i want to run this routine many times i will have to read the characters lots of times... its gonna be time consuming...
3. I have a problem on typing a file on screen.
I read character by character and print it on screen.
it works great if the thext is sequential. If for example i copy the text from this post and paste it in a file and run the type code, i get all type of characters on screen. i guess it has something to do with changing the line. How can i correct that?
Comments
the directory metadata; just need to access the right variable).
2. Not presently; slightly harder to add but doable.
3. Could you elaborate? I don't fully understand the problem.
just adding a couple lines to Mike Green's version of rockiki's code does it...
file just posted here:
http://forums.parallax.com/showthread.php?p=811555
it's one of the files in the first attachement...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
For seeking in a file I wrote this little piece of code for my mp3 player project. I wrote this for Mike Green's fsrwFemto version of the SD driver, but I don't think there is any reason it shouldn't work in Rokicki's original code. Just paste this method into the fsrw object. When you call it, it skips forward in the currently open file by the parameter you pass it.
As for the file size, you should be able to make a method that reads the filesize variable. Something like this:
This should work if I correctly remember what the filesize variable stores. I haven't tested it though, so no guarantees it will actually work.
-Kit
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PHRED, FIRST Team 847, Member
Go -> PHRED
First of all filesize question=silly
there is allready a filesize variable.
As kit said
Pub fsize
return filesize
does the trick.
Havent tried ur seek method yet kit. i'll post my results when ready.
@rokicki
What i am trying to do is:
Lets say i have a text file
Test.txt
and a text file
test1.txt
if i run this code
for the test.txt i get the contents of test.txt on my tv.
but if i run it for test1.txt i get several characters but not necessarily the contents of test1.txt
carriage returns but not line feeds, or something like that, and the text.out
routines are not interpreting them the way you want.
If you can't figure it out from that, post the full code (and include your test file)
and we'll take a look.