I'm trying to access information about a specific file - in particular, the creation date/time.
I can do this by generating a directory listing (thanks to this forum for their help in resolving my "dir /s" query), but for some reason, I get different date/times when looking at the file on different media (rounding / truncation maybe?).
I looked in the online help, and found information about reading through the contents of a directory, and deriving such attributes as creation date/time, but could not see how to get this for a *specific* file.
(And after looking at other threads in this forum, I found this wiki - http://www.bbcbasic.co.uk/wiki/doku.php ... nd_20files - and bookmarked it - but couldn't see an answer to this question there.)
Getting file information
Re: Getting file information
Hi Simon,
The technique shown in the manual under "Listing the disk directory" should allow you to find what you need?
Best wishes,
D
The technique shown in the manual under "Listing the disk directory" should allow you to find what you need?
Best wishes,
D
Re: Getting file information
Hi Simon,
Sorry to be so long getting back on this. With a bit of playing, and help from Richard, I've come up with this, which may help. It's a bit fiddly because some data gets returned in 16 bits, so an integer picks up two, while others are returned in 64 bits, so you need a long integer. Weirdly, the file size is 64 bits, but the "wrong way round", so you need to read it as high and low sections.
I'll have a think about making a function which takes a filetime and a systemtime structure and returns the requested bit of information, but I'll have to swot up a bit on passing structures to functions....
Best wishes,
D
Sorry to be so long getting back on this. With a bit of playing, and help from Richard, I've come up with this, which may help. It's a bit fiddly because some data gets returned in 16 bits, so an integer picks up two, while others are returned in 64 bits, so you need a long integer. Weirdly, the file size is 64 bits, but the "wrong way round", so you need to read it as high and low sections.
I'll have a think about making a function which takes a filetime and a systemtime structure and returns the requested bit of information, but I'll have to swot up a bit on passing structures to functions....
Best wishes,
D
Code: Select all
DIM FileAttributes{atts%,creation%%,last_access%%,last_write%%,fsize_High%,fsize_Low%}
DIM SystemTime{Y_M%,DoW_D%,Hr_Min%,Sec_MS%}
f$=@dir$+"test_for_file_attributes.bbc"
SYS "GetFileAttributesExA",f$,0,FileAttributes{}
PRINT "File size: ";FileAttributes.fsize_Low%
PRINT "Creation time:"; FileAttributes.creation%%
PRINT "Last access time:"; FileAttributes.last_access%%
PRINT"For me, the last access time comes up the same as creation time!"
PRINT "Last write time:"; FileAttributes.last_write%%
SYS "FileTimeToSystemTime",^FileAttributes.creation%%,SystemTime{} TO flag%
IF flag%=0 THEN PRINT "FAILED!"
PRINT "Created in year: ";SystemTime.Y_M% AND &FFFF
PRINT "Created in month: ";SystemTime.Y_M% >>16
PRINT "Created on DoW: ";SystemTime.DoW_D% AND &FFFF
PRINT "Created on Day: ";SystemTime.DoW_D% >>16
PRINT "Created at Hr: ";SystemTime.Hr_Min% AND &FFFF
PRINT "Created at Min: ";SystemTime.Hr_Min% >>16
SYS "FileTimeToSystemTime",^FileAttributes.last_write%%,SystemTime{} TO flag%
IF flag%=0 THEN PRINT "FAILED!"
PRINT "Modified in year: ";SystemTime.Y_M% AND &FFFF
PRINT "Modified in month: ";SystemTime.Y_M% >>16
PRINT "Modified on DoW: ";SystemTime.DoW_D% AND &FFFF
PRINT "Modified on Day: ";SystemTime.DoW_D% >>16
PRINT "Modified at Hr: ";SystemTime.Hr_Min% AND &FFFF
PRINT "Modified at Min: ";SystemTime.Hr_Min% >>16
-
- Posts: 64
- Joined: Tue 03 Apr 2018, 12:07
- Location: Belgium
Re: Getting file information
Hi D. ,
On 22 Mar 2019 you 've posted some prototype code that deals with the FileAttributes.
I think you were still trying to solve a few details. I 've just tried the code you 've posted and it runs but doesn't produce any correct data.
Did you follow through on this ? If yes, would you be prepared to share the result ?
I could use a function that returns file attributes for a specific file (creation date, ...)
regards,
Edja
On 22 Mar 2019 you 've posted some prototype code that deals with the FileAttributes.
I think you were still trying to solve a few details. I 've just tried the code you 've posted and it runs but doesn't produce any correct data.
Did you follow through on this ? If yes, would you be prepared to share the result ?
I could use a function that returns file attributes for a specific file (creation date, ...)
regards,
Edja
Re: Getting file information
DDRM's code returns correct data for me:
Code: Select all
Created in year: 2020
Created in month: 2
Created on DoW: 3
Created on Day: 26
Created at Hr: 16
Created at Min: 24
Modified in year: 2020
Modified in month: 2
Modified on DoW: 3
Modified on Day: 26
Modified at Hr: 16
Modified at Min: 24
Of course on the date that the file was created Daylight Saving Time was not in effect (in the UK) so it really was created at 16:24 by the clock, but the conversion to 'local time' is done according to the time zone now, not when the file was created!