That is very slow.
For example in Python you need only one function for that and I suppose there is only one file access to read out all informations: https://www.tutorialspoint.com/python/os_stat.htm
Are there Windows and Mac OS API functions that can do the same?
Yeah! Thanks! Just what I expected! This speeds up my file scaning tool by a factor of 4 !!!
It is possible to replace that buf()-array with a real structure?
I found that, but I am not sure which size 32/64 the single entries have:
struct stat { /* when _DARWIN_FEATURE_64_BIT_INODE is defined */
dev_t st_dev; /* ID of device containing file */
mode_t st_mode; /* Mode of file */
nlink_t st_nlink; /* Number of hard links */
ino_t st_ino; /* File serial number 64 bits */
uid_t st_uid; /* User ID of the file */
gid_t st_gid; /* Group ID of the file */
dev_t st_rdev; /* Device ID */
struct timespec st_atimespec; /* time of last access */
struct timespec st_mtimespec; /* time of last data modification */
struct timespec st_ctimespec; /* time of last status change */
struct timespec st_birthtimespec; /* time of file creation(birth) added */
off_t st_size; /* file size, in bytes */
blkcnt_t st_blocks; /* blocks allocated for file */
blksize_t st_blksize; /* optimal blocksize for I/O */
uint32_t st_flags; /* user defined flags for file */
uint32_t st_gen; /* file generation number */
int32_t st_lspare; /* RESERVED: DO NOT USE! */
int64_t st_qspare[2]; /* RESERVED: DO NOT USE! */
};
I didn't tested it, but may be you can use ExamineDirectory() with your filename as pattern, and use the DirectoryEntryDate()/Size() function it should be faster as it's only one call.
ImportC ""
stat64(path.p-ascii, *buf)
getpwuid(uid)
getgrgid(gid)
EndImport
Structure timespec
tv_sec.i
tv_nsec.i
EndStructure
Structure stat64
st_dev.l; /* ID of device containing file */
st_mode.w; /* Mode of file */
st_nlink.w; /* Number of hard links */
st_ino.q; /* File serial number */
st_uid.l; /* User ID of the file */
st_gid.l; /* Group ID of the file */
st_rdev.i; /* Device ID */
st_atimespec.timespec; /* time of last access */
st_mtimespec.timespec; /* time of last data modification */
st_ctimespec.timespec; /* time of last status change */
st_birthtimespec.timespec; /* time of file creation(birth) */
st_size.q; /* file size, in bytes */
st_blocks.q; /* blocks allocated for file */
st_blksize.l; /* optimal blocksize for I/O */
st_flags.l; /* user defined flags for file */
st_gen.l; /* file generation number */
st_lspare.l; /* RESERVED: DO NOT USE! */
st_qspare.q[2]; /* RESERVED: DO NOT USE! */
EndStructure
stat64("MyFile", @stats.stat64)
Debug "File size : " + Str(stats\st_size)
Debug "User name : " + PeekS(PeekI(getpwuid(stats\st_uid)), -1, #PB_Ascii)
Debug "Group name : " + PeekS(PeekI(getgrgid(stats\st_gid)), -1, #PB_Ascii)
Debug "Last access : " + FormatDate("%yyyy/%mm/%dd", stats\st_atimespec\tv_sec)
Did you find out the necessity for the alignment only recently?
Sorry for not directly linking to your last posting in that thread.
Shardik wrote:Did you find out the necessity for the alignment only recently?
Sorry for not directly linking to your last posting in that thread.
I should have read that thread more carefully
I overlooked my own post and didn't even remember I had looked at stat64 before.
Anyway, I chose a different way in that post to solve the alignment.
Even while st_rdev reports 4 bytes in XCode I typed it as .i so it would become 8 bytes on x64.
When it comes to the alignment the effect is the same as my solution in this thread but the solution in the other thread looks cleaner I guess.
Fred wrote:I didn't tested it, but may be you can use ExamineDirectory() with your filename as pattern, and use the DirectoryEntryDate()/Size() function it should be faster as it's only one call.
Yes! Very good hint. It seems that is the thing I need. I had not noticed these commands yet...
Thanks also @Wilbert and @Shardik for your informations!
Always good to speed things up, but the Windows __stat64 structure does not match what is listed here.
I get filesize from \st_rdev. Just pause the code and look at the structure with the memoryviewer.
Just use the PB functions:
iDir = ExamineDirectory(#PB_Any, Path$, Pat$)
If iDir
While NextDirectoryEntry(iDir)
;...
FinishDirectory(iDir)
or Windows api:
WIN32_FIND_DATA struct while stepping through a directory/subdirs with FindFirstFile()/FindNextFile().
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Fred wrote:I didn't tested it, but may be you can use ExamineDirectory() with your filename as pattern, and use the DirectoryEntryDate()/Size() function it should be faster as it's only one call.
I don't know if this is what you mean't... but this works as well as I need. Thanks Fred.
My timer results on a dual Xeon E5-2670 was 179 msecs. using the Debugger (below).
Note: You can leave out the Hi Res timer, if you wish.