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

frktons

If I want to know when a file was created, what size is it, and so on,
without opening it, what API should I use?

Could anyone post an example of calling the API and getting the info
from the file?

Thanks

Frank
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

Donkey

"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

frktons

Quote from: Donkey on December 24, 2012, 01:10:01 PM
FindFirstFile will get all of that information.

Thanks Edgar.
It seems other APIs as well give the same info:
GetFileTime(), GetFileInformationByHandle() among  them.

I'll give them a try.
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

you might also like GetFileAttributesEx   :P

it gives you the 3 file times, the attribute, and the size
and, it's fast

frktons

Quote from: dedndave on December 24, 2012, 01:45:09 PM
you might also like GetFileAttributesEx   :P

it gives you the 3 file times, the attribute, and the size
and, it's fast

It looks like all the APIs give all these info. Which one is faster I can't tell.
I suppose all of them are quite fast.
:P
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 use GetFileAttributesEx - normally i just want the file size - sometimes the attribute also

in the old forum, we did some testing and it was fastest
however, i think that test was "what is the fastest way to get file size"
it did not take the other data into account

as i recall, FindFirstFile was slowest

frktons

Quote from: dedndave on December 24, 2012, 03:47:02 PM
i use GetFileAttributesEx - normally i just want the file size - sometimes the attribute also

in the old forum, we did some testing and it was fastest
however, i think that test was "what is the fastest way to get file size"
it did not take the other data into account

as i recall, FindFirstFile was slowest

Dave, if you have an example of getting file info with GetFileAttributesEx
and display date of last write, and file size, it'd be nice.
I've seen some examples using the stack, posted by you and Jochen, but
I'd prefer the use of the structure as it is declared.

Messing with the stack is not my actual priority.  :biggrin:
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

just for info....

GET_FILEEX_INFO_LEVELS is an enumeration type
MASM does not have an exact replacement for enumerations
it's sort of like a cross between a structure and an equate
GetFileExInfoStandard is the first enumeration member, so the value is 0 - it's the only valid value

give me a second.....

jj2007

Quote from: dedndave on December 25, 2012, 12:34:01 AM
MASM does not have an exact replacement for enumerations

MASM has lots of crazy stuff ;-)

        Enum              IdMenuNew, IdMenuSave, IdMenuCopy, IdEdit, IdList, IdButton, ...
        SetGlobals       hInstG, hMain, hList, rc:RECT, ...

dedndave

#9
give this a try

Usage:
FileInfo <filename>
C:\Masm32\Asm>FileInfo blah
File Not Found

C:\Masm32\Asm>FileInfo
No File Specified

C:\Masm32\Asm>FileInfo FileInfo.asm
nFileSize:        00000000000019E1h
ftCreationTime:   MON 12-24-2012 13:23:29.927
ftLastAccessTime: MON 12-24-2012 14:47:16.630
ftLastWriteTime:  MON 12-24-2012 14:46:13.380

FILE_ATTRIBUTE_ARCHIVE


C:\Masm32\Asm>FileInfo C:\Windows
nFileSize:        0000000000000000h
ftCreationTime:   WED 2-23-2005 11:59:56.609
ftLastAccessTime: MON 12-24-2012 14:51:19.177
ftLastWriteTime:  SUN 12-23-2012 16:46:53.6

FILE_ATTRIBUTE_DIRECTORY


EDIT: updated the attachment
fixed the command line parser
improved the way carriage return/line feeds are used

frktons

Quote from: dedndave on December 25, 2012, 01:48:32 AM
give this a try

Usage:
FileInfo <filename>
C:\Masm32\Asm>FileInfo blah
File Not Found

C:\Masm32\Asm>FileInfo
No File Specified

C:\Masm32\Asm>FileInfo FileInfo.asm
nFileSize:        00000000000019E1h
ftCreationTime:   MON 12-24-2012 13:23:29.927
ftLastAccessTime: MON 12-24-2012 14:47:16.630
ftLastWriteTime:  MON 12-24-2012 14:46:13.380

FILE_ATTRIBUTE_ARCHIVE


C:\Masm32\Asm>FileInfo C:\Windows
nFileSize:        0000000000000000h
ftCreationTime:   WED 2-23-2005 11:59:56.609
ftLastAccessTime: MON 12-24-2012 14:51:19.177
ftLastWriteTime:  SUN 12-23-2012 16:46:53.6

FILE_ATTRIBUTE_DIRECTORY


When I type "FileInfo FileInfo.asm" in the command line,
It just says : "File Not Found".
Dave what's going on?
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

is it in the current folder ?
if not, you must specify the full pathname
also - i made a little mistake in the command-line parser
if you put more than one space in there, it will fail   :P

updated the previous attachment

frktons

Quote from: dedndave on December 25, 2012, 12:18:11 PM
is it in the current folder ?
if not, you must specify the full pathname
also - i made a little mistake in the command-line parser
if you put more than one space in there, it will fail   :P

updated the previous attachment

:t
Now it works. I'll see if I can understand something.
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

here is one with a more advanced parser
it will accomodate use in batch files where you need to surround paths containing spaces by double-quotes
C:\Masm32\Asm>"FileInfo" "C:\Program Files"
nFileSize:        0000000000000000h
ftCreationTime:   WED 2-23-2005 12:4:1.921
ftLastAccessTime: TUE 12-25-2012 3:35:33.640
ftLastWriteTime:  MON 12-24-2012 3:18:21.427

FILE_ATTRIBUTE_READONLY
FILE_ATTRIBUTE_DIRECTORY

shantanu_gadgil

From what I remember, GetFile... function sometimes (mostly?) fail for system critical files like pagefile.sys, hiberfil.sys, etc. FindFirstFile works in such cases.

Typically what I used to do was (don't remember where the code is now) to write a wrapper function with my own naming convention, logging messages etc., which internally calls FindFirstFile. Even if it is just for a single file!  :biggrin: :icon_eek:

HTH,
Shantanu