Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Difference between FileGet and FileGetByte

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-28-2008, 12:27 PM
Senior Member
 
Join Date: Apr 2007
Location: Copenhagen
Posts: 173
Default Difference between FileGet and FileGetByte

I am trying to read a shortcut file to see what file it points to. If I use FileGet then (after parsing) I get the following:

C:\Documents and Settings\bjf\Desktop\Dyrevelferd, et vitenskapelig perspektiv (Bj?rn Forkman).ppt

If on the other hand I use FileGetByte I get the following:

C:\Documents and Settings\bjf\Desktop\Dyrevelferd, et vitenskapelig perspektiv (Björn Forkman).ppt

which is the correct filename. But FileGet is of course much faster, so I would like to use it (it is not possible to use FileReadToEnd etc., shortcut-files are very strange to work with )

Any neat solution to this?

all the best / Björn
Reply With Quote
  #2 (permalink)  
Old 10-28-2008, 03:34 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by BjornF View Post
Any neat solution to this?
As you haven't shown us the parsing code that we can sees what leads to these results then no! -
Reply With Quote
  #3 (permalink)  
Old 10-28-2008, 04:09 PM
Senior Member
 
Join Date: Apr 2007
Location: Copenhagen
Posts: 173
Default

Sorry, here it is. (Although I don't think that is the problem - and possibly parsing is an overly ambitious word )

Code:
    FileOpen(c1,Ftxt,cRandom)
txt=FileGet(c1,
0,FileSize(Ftxt))
StartPos=StrIndexOf(txt,
"C:\",0)
If startpos>0 Then
    txt=SubString(txt,StartPos,StrLength(txt)-startpos)
Else
    txt=
"can't find the c:\"
End If
textbox1.Text=txt

("1000" is just used to be certain that I have read the whole file)

Code:
    FileOpen(c1,Ftxt,cRandom)
Do Until i=1000        
    i=i+
1
    x=FileGetByte(c1,i)
    textbox2.Text=textbox2.Text&
Chr(x)
Loop

Björn
Reply With Quote
  #4 (permalink)  
Old 10-28-2008, 05:14 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

It looks like a character encoding problem and is probably by design.

FileGet is reading the string with ASCII encoding which only comprises the character Chr(0) to Chr(127) and so doesn't recognise the "ö" character as being in the ASCII character set and so replaces it with a question mark. FilePut also only writes ASCII encoding so at least the two are symmetrical.

Reading it a byte at a time preserves the "ö" because it reads each byte of the file as a number and adds it to the text as a character so all the characters from 0 to 255 will come through. This would probably fail to return the correct characters if the string was UTF8 encoded and contained any multi-byte characters.
Reply With Quote
  #5 (permalink)  
Old 10-28-2008, 08:42 PM
Senior Member
 
Join Date: Apr 2007
Location: Copenhagen
Posts: 173
Default

Hmm, so if I understand you right there is no way around this then...

all the best / Björn
Reply With Quote
  #6 (permalink)  
Old 10-28-2008, 09:05 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by BjornF View Post
Hmm, so if I understand you right there is no way around this then...
You should be OK reading the string as bytes, the worst case is that the filename you get back wouldn't be valid. It might be worth trying to read the filename as bytes and test each byte for a value of zero. Zero is usually used to indicate a string terminator in native Windows strings. I wouldn't be bothered about speed in reading it a byte at a time. The difference won't matter for your appication.
Reply With Quote
  #7 (permalink)  
Old 10-29-2008, 08:34 AM
Senior Member
 
Join Date: Apr 2007
Location: Copenhagen
Posts: 173
Default

Thank you for the answer Graham.

I do get valid filenames when reading them with filegetbyte, so no problem there. It does take longer - unfortunately the short cut files contain a lot of other information, and there are also a number of them (around 250 in my Recent Files folder), but it isn't critical in any way.

The idea of looking for a zero byte is good, I'll use that for the end of the filename (the file is always finished with four zero bytes in a row so that should give me the end of the file instead of the "1000" I used in the example).

Thank you for the help / Björn
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
if FileGetByte()=0 then... BjornF Questions (Windows Mobile) 2 10-07-2008 06:36 PM
Problem with FileGet on Device BerndB Questions (Windows Mobile) 10 05-11-2008 08:51 AM
What's The Difference? Louis Chit Chat 1 03-08-2008 08:38 AM
Formsize no difference PC/PPC tvrman Questions (Windows Mobile) 2 10-06-2007 05:04 PM
Difference Between Two Dates dvanwig Questions (Windows Mobile) 7 08-02-2007 04:29 AM


All times are GMT. The time now is 03:02 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0