Hi all,
when I try to determine the lenhth of a file I use following code:
int flength(char *filename) { FILE* file; FINFO info; file = fopen(filename,"r"); if(!file) { return(-1); } fclose(file); info.fileID = 0; while(ffind(filename, &info)==0); if(info.fileID == 0) { return(-1); } return(info.size); }
All works fine as long as I use simple filenames like "F:test.txt". As soon as I try to do this with filenames including subfolders ("F:\\test\\test.txt") it fails.
Is there another way to determine the length of a file? Why won't ffind() not work with subfolders?
Any ideas? Marco
Flash-FS rules for file names are rather confusing. This is what I once got from Keil support:
"The filename case handling was described by the developers like that:
- if name is less than or equal 8 characters and extension less or equal to 3 and only one case characters, (all lower or all upper) file is coded as short filename which only contains upper cases letters so: test.txt => TEST.TXT TEST.TXT => TEST.TXT
- if case of letters are mixed it is automatically considered a long filename and filename is encoded as it was written Test.txt => Test.txt teSt.txt => teSt.txt
- if there are more than 8 characters in filename or more than 3 in extension or more . (dots) in filename it is encoded as long filename
- filename Test.txt is different than filename tEst.txt as they are both long and encoded as they were written
"
Hi,
stdio gives:
fseek(fp, 0, SEEK_END); fileSize = ftell(fp);
www.keil.com/.../rlarm_fs_func_fileio.htm
BR, /th.
ok, not exactly the answer to your text but an answer to the question :-)
Thanks Thorsten,
fseek/ftell works fine!
For now my problem is solved, though I still don't understand why ffind() won't work....
Thanks for sharing, Marco
As far as I understand, ffind work just like the proposed solution that "works". Your fopen might still failed unless you follow the naming conventions of Flash-FS.