How do you find the creation date of a file in windows?
Also can you find the size of a file in a similar fashion?
How do you find the creation date of a file in windows?
Also can you find the size of a file in a similar fashion?
There's no standard way of doing it so you'll have to use the Windows API and if you haven't done that before you're not gonna like this...
http://msdn.microsoft.com/library/de...tributesex.asp
http://msdn.microsoft.com/library/de...filesizeex.asp
OK. I guess the easiest way of doing it is to use MSDOS and output
the contents of a "dir" command into a file and then read the data
you want out of that file. Probably much easier and just as quick.
Taking the output from another program is usually considered insecure, slow and tedious.
I also noticed that GetFileAttributesEx can fetch filesize too so that makes things easier. Here's a quick example that gets creation date and filesize in bytes from the file given as the first command line argument:
Code:#include <stdio.h> #include <windows.h> int main (int argc, char** argv) { WIN32_FILE_ATTRIBUTE_DATA attr; SYSTEMTIME creation; if (argc < 2) return 1; GetFileAttributesEx(argv[1], GetFileExInfoStandard, &attr); FileTimeToSystemTime(&attr.ftCreationTime, &creation); printf("Created: %04d-%02d-%02d %02d:%02d:%02d\n" "Size: %d bytes\n", creation.wYear, creation.wMonth, creation.wDay, creation.wHour, creation.wMinute, creation.wSecond, attr.nFileSizeLow); return 0; }
Yes but don't I have to spend huge pile of money on buying cr*p
from Microsoft to do this?
There would be a bit of an overhead doing it my way, but not much
that you would notice.
If I wanted to find the biggest or latest file in a folder I could do
a sorted dir in msdos into a file then read the first line the file.
A bit more work for files above a certain value.
(I may need to do to this for my poker hand analysis program )
Which compiler do you have?
dev-c++ can call win32 API functions just as well as any other
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
It's free and pretty much all compilers have it, Microsoft hasn't gone THAT far... yet.
I have djgcc or gcc or whatever it's called.Originally Posted by Salem
I have also tried Dev-C++ (I think) but I found it a bit
too overblown.
I may try it again but I could probably do in half the time
with GCC and msdos.
GCC doesn't appear to have it.
Don't know anything about djgpp but for MinGW32 you'll have to download the Windows API library seperately so I'm guessing that's what you need to do.
What is wrong with the stat function?
~Sven
Windows XP Home Edition - Dev-C++ 4.9.9.2
board.theprogrammingsite.comOriginally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie
But DJGPP has it.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.