PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

obtaining file size & date?

Unfortunately, the tutorial on how to obtain a list of files from a folder (on arianesoft.ca) does not show how to obtain details like the file size and date.

The WIN32_FIND_DATA msdn pages are not very helpful, because it is not clear how to convert DWORD nFileSizeHigh and FILETIME ftLastWriteTime to PPL variables.

Can anybody help here?

cheers,
RdR
Hi,

There is a topic about obtaining the filesize on arianesoft.ca already:

func FileSize(filename$)
f$ = fopen(filename$, "r");
fseek(f$, 1, SEEK_END);
filesize$ = ftell(f$);
fclose(f$);
return (filesize$);
end;

With WIN32_FIND_DATA you can obtain the date and file size too:

struct(lpData$, WIN32_FIND_DATA);

handle$ = FindFirstFile("c:\\temp\\ *.*", &lpData;$);
if(handle$ == INVALID_HANDLE_VALUE)
ShowMessage("No files found");
return(true);
end;

struct(UTC$, SYSTEMTIME);
struct(l$, SYSTEMTIME);

msg$ = "";
result$ = 1;
while(result$ > 0)
FileTimeToSystemTime(lpData.ftLastWriteTime$, &UTC;$);
SystemTimeToTzSpecificLocalTime(NULL, UTC$, &l;$);

msg$ = msg$ + lpData.cFilename$+" " + t.wMonth$ + "/" + l.wDay$ + "/" + l.wYear$ + " " + l.wHour$ + ":" + t.wMinute$ + "\n";

result$ = FindNextFile(handle$, & lpData$);
end;

FindClose(handle$);

ShowMessage(msg$);
Thanks for that, Kornalius.

I tried it out, but unfortunately got a strange syntax error. Here's the little program I wrote and the syntax error that resulted:

Code:

#include "console.ppl"

func WinMain
InitConsole;
ShowConsole;

struct(fd$, WIN32_FIND_DATA);
struct(UTC$, SYSTEMTIME);
struct(l$, SYSTEMTIME);

i$ = FindFirstFile("*.*", &fd;$);
if (i$ != INVALID_HANDLE_VALUE)
repeat
FileTimeToSystemTime(fd.ftLastWriteTime$, &UTC;$);
SystemTimeToTzSpecificLocalTime(NULL, UTC$, &l;$);
writeln(char(fd.cFilename$)+"\t" + fd.nFileSizeHigh$ + t.wMonth$ + "/" + l.wDay$ + "/" + l.wYear$ + "\t" + l.wHour$ + ":" + t.wMinute$);
until (FindNextFile(i$, &fd;$) == false);
FindClose(i$);
end;

return (true);
end;


When I run this, the error is:

Code:

[Syntax error at 'SYSTEMTIMETOTZSPECIFICLOCALTIME' (15,8)]
[: or , expected at ';' (15,56 )]



Any ideas?

cheers,
RdR
Looks like the function is not declared.

Try adding this line before func WinMain:

#declare SystemTimeToTzSpecificLocalTime kndll SystemTimeToTzSpecificLocalTime 3 1
Thanks, Kornalius.

The declaration fixed that problem. I fixed a few other things also (program below). The only thing I couldn't find was a pre-declared constant for MAXDWORD, so I declared a global variable for that.

The calculation of filesize is according to the msdn explanation. I checked the sizes against the file properties in File Explorer, and it seems to return the correct value.

cheers,
RdR

Code:

#include "console.ppl"
#declare SystemTimeToTzSpecificLocalTime kndll SystemTimeToTzSpecificLocalTime 3 1

func WinMain
InitConsole;
ShowConsole;

struct(fd$, WIN32_FIND_DATA);
struct(UTC$, SYSTEMTIME);
struct(l$, SYSTEMTIME);
global( MAXDWORD$);
MAXDWORD$ = 0xFFFFFFFF;
i$ = FindFirstFile("*.*", &fd;$);
if (i$ != INVALID_HANDLE_VALUE)
repeat
FileTimeToSystemTime(fd.ftLastWriteTime$, &UTC;$);
SystemTimeToTzSpecificLocalTime(NULL, UTC$, &l;$);
z$ = (fd.nFileSizeHigh$ * (MAXDWORD$ +1)) + fd.nFileSizeLow$ ;
writeln(char(fd.cFilename$)+"\t" + z$ + "\t" + l.wMonth$ + "/" + l.wDay$ + "/" + l.wYear$ + "\t" + l.wHour$ + ":" + l.wMinute$);
until (FindNextFile(i$, &fd;$) == false);
FindClose(i$);
end;

return (true);
end;
UPDATE: when I run this program on the pocket pc (dopod 838Pro) the date and time results are all zero.

Is there a difference in how the structures, etc. work on the pocket pc?

cheers,
RdR
The problem here is that SystemTimeToTzSpecificLocalTime is not defined in WinCE.

This should work better:

Code:
#include "console.ppl"

func WinMain
InitConsole;
ShowConsole;

struct(fd$, WIN32_FIND_DATA);
struct(UTC$, SYSTEMTIME);
struct(LFT$, FILETIME);
struct(l$, SYSTEMTIME);
global(MAXDWORD$);
MAXDWORD$ = 0xFFFFFFFF;
i$ = FindFirstFile("\\*.*", &fd;$);
if (i$ != INVALID_HANDLE_VALUE)
repeat
FileTimeToLocalFileTime(fd.ftLastWriteTime$, &LFT;$);
FileTimeToSystemTime(LFT$, &l;$);
z$ = (fd.nFileSizeHigh$ * (MAXDWORD$ +1)) + fd.nFileSizeLow$ ;
writeln(char(fd.cFilename$)+"\t" + z$ + "\t" + l.wMonth$ + "/" + l.wDay$ + "/" + l.wYear$ + "\t" + l.wHour$ + ":" + l.wMinute$);
until (FindNextFile(i$, &fd;$) == false);
FindClose(i$);
end;

return (true);
end;
That worked!
Thanks for all your help.

BTW, I tried ordering the Pro version just now, but had a lot of trouble with esellerate. Kept asking for cookies for PayPal, but no matter what things I fiddled with on the browser and firewall -- it didn't want to work. Most annoying: I don't have that problem with other sites -- gave up in the end.

I'll try again some other day.

cheers,
RdR