C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-02-2006, 05:51 PM   #1
Fountain of knowledge.
 
Join Date: May 2006
Posts: 662
File creation date (in windows 98 and XP)

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?
esbo is offline   Reply With Quote
Old 05-02-2006, 06:51 PM   #2
Mad
 
OnionKnight's Avatar
 
Join Date: Jan 2005
Location: Umeå, Sweden
Posts: 555
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
OnionKnight is offline   Reply With Quote
Old 05-02-2006, 07:03 PM   #3
Fountain of knowledge.
 
Join Date: May 2006
Posts: 662
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.
esbo is offline   Reply With Quote
Old 05-02-2006, 07:43 PM   #4
Mad
 
OnionKnight's Avatar
 
Join Date: Jan 2005
Location: Umeå, Sweden
Posts: 555
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;
}
OnionKnight is offline   Reply With Quote
Old 05-02-2006, 08:41 PM   #5
Fountain of knowledge.
 
Join Date: May 2006
Posts: 662
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 )
esbo is offline   Reply With Quote
Old 05-03-2006, 12:48 AM   #6
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,699
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.

Salem is offline   Reply With Quote
Old 05-03-2006, 02:26 AM   #7
Mad
 
OnionKnight's Avatar
 
Join Date: Jan 2005
Location: Umeå, Sweden
Posts: 555
It's free and pretty much all compilers have it, Microsoft hasn't gone THAT far... yet.
OnionKnight is offline   Reply With Quote
Old 05-03-2006, 08:53 AM   #8
Fountain of knowledge.
 
Join Date: May 2006
Posts: 662
Quote:
Originally Posted by Salem
Which compiler do you have?
dev-c++ can call win32 API functions just as well as any other
I have djgcc or gcc or whatever it's called.

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.
esbo is offline   Reply With Quote
Old 05-03-2006, 08:57 AM   #9
Fountain of knowledge.
 
Join Date: May 2006
Posts: 662
GCC doesn't appear to have it.
esbo is offline   Reply With Quote
Old 05-03-2006, 09:03 AM   #10
Mad
 
OnionKnight's Avatar
 
Join Date: Jan 2005
Location: Umeå, Sweden
Posts: 555
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.
OnionKnight is offline   Reply With Quote
Old 05-03-2006, 10:02 AM   #11
Registered User
 
00Sven's Avatar
 
Join Date: Feb 2006
Posts: 127
What is wrong with the stat function?
~Sven
__________________
Windows XP Home Edition - Dev-C++ 4.9.9.2
Quote:
Originally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie
int fflush(FILE *stream)
On an output stream, fflush causes any buffered but unwritten data to be written; On an input stream, the effect is undefined. It returns EOF for a write error, and zero otherwise. fflush(NULL) flushes all output streams.
board.theprogrammingsite.com
00Sven is offline   Reply With Quote
Old 05-03-2006, 02:26 PM   #12
Mad
 
OnionKnight's Avatar
 
Join Date: Jan 2005
Location: Umeå, Sweden
Posts: 555
It's a POSIX function.
OnionKnight is offline   Reply With Quote
Old 05-03-2006, 05:27 PM   #13
Frequently Quite Prolix
 
dwks's Avatar
 
Join Date: Apr 2005
Location: Canada
Posts: 7,698
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.
dwks is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Program works on Windows XP and 2000, not on 98 or ME MidnightlyCoder C++ Programming 7 03-10-2006 03:36 PM
Windows 98/2000 programming in Windows XP Bill83 Windows Programming 3 07-22-2005 02:16 PM
dual boot Win XP, win 2000 Micko Tech Board 6 05-30-2005 02:55 PM
FlashWindowEx not declared? Aidman Windows Programming 3 05-17-2003 02:58 AM
Windows 98 api vs windows XP Shadow12345 Windows Programming 3 10-01-2002 05:58 AM


All times are GMT -6. The time now is 05:53 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22