News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

What's the API to read File Info without opening it?

Started by frktons, December 24, 2012, 11:54:27 AM

Previous topic - Next topic

dedndave

thanks for the tip Shantanu   :t

GetFileAttributesEx seems to work on boot.ini, but not pagefile.sys
it even works on C:\   :P

what you could do is use GetFileAttributesEx for speed
if that fails, then use FindFirstFile to verify whether or not the file really exists

typically, when i use GetFileAttributesEx, i am using it on a config file or some other similar data file, though

frktons

Probably I'm not going to use these functions on critical
files, but it is good to know anyway that on some files
the functions can fail.

Thanks and Happy Holidays.
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

dedndave

i played with it anyways
the WIN32_FIND_DATA structure is a superset of the WIN32_FILE_ATTRIBUTE_DATA structure
so - the code is pretty simple
while i was at it, i made some more improvements on the parser
i made sure to use LODSB, just for Hutch 

C:\>"documents and settings\fileinfo" "c:\pagefile.sys
nFileSize:        000000005F400000h
ftCreationTime:   MON 12-10-2012 0:23:34.390
ftLastAccessTime: TUE 12-25-2012 13:32:44.125
ftLastWriteTime:  TUE 12-25-2012 13:32:44.125

FILE_ATTRIBUTE_HIDDEN
FILE_ATTRIBUTE_SYSTEM
FILE_ATTRIBUTE_ARCHIVE


the reason i spent time on this is i will use the parse code for future projects
and - it gave me a break from my "big" project - back to that tomorrow   :P

sinsi

For a test of the relative speeds of those functions try to get the file information over a network.
This will give you an idea of overhead  :lol:

dedndave

that latest version uses FindFirstFile only if GetFileAttributesEx fails

really, you have to tailor your code for the specific application, as always

frktons

Quote from: dedndave on December 26, 2012, 02:52:42 PM
that latest version uses FindFirstFile only if GetFileAttributesEx fails

really, you have to tailor your code for the specific application, as always

Well done, Dave :t
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

jj2007

FFF finds the *.sys files. As to speed, FindFirstFile is a bit slower because, as the name says, it first has to find the file that matches e.g. *.doc - and that costs time. I have difficulties to construct a real life case where the speed difference matters, i.e. where you have already a complete list of 100,000 files and you still need further info...

include \masm32\MasmBasic\MasmBasic.inc        ; download
        Init        ; ### show files in C:\* ###
        GfNoRecurse=1        ; root only
        GetFiles C:\*
        xchg eax, ecx
        Print "Files in the root:"
        .Repeat
                PrintLine Files$(ecx)
                dec ecx
        .Until Sign?
        Inkey
        Exit
end start

Files in the root:
C:\pagefile.sys
C:\ntldr
C:\NTDETECT.COM
C:\MSDOS.SYS
C:\IO.SYS
C:\install.ini
C:\hiberfil.sys
C:\globdata.ini
C:\CONFIG.SYS
C:\Bootfont.bin
C:\boot.ini
C:\AUTOEXEC.BAT

frktons

Quote from: jj2007 on December 27, 2012, 04:56:25 AM
FFF finds the *.sys files. As to speed, FindFirstFile is a bit slower
because, as the name says, it first has to find the file that
matches e.g. *.doc - and that costs time. I have difficulties
to construct a real life case where the speed difference matters,
i.e. where you have already a complete list of 100,000 files and
you still need further info...

Thanks Jochen for the explanation.

In this case, and for a rare coincidence, I'm not looking
for the fastest API, but just for the suitable ones.
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama