File creation date (in windows 98 and XP)

This is a discussion on File creation date (in windows 98 and XP) within the C Programming forums, part of the General Programming Boards category; How do you find the creation date of a file in windows? Also can you find the size of a ...

  1. #1
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794

    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?

  2. #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

  3. #3
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    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.

  4. #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;
    }

  5. #5
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    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 )

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #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.

  8. #8
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    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.

  9. #9
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    GCC doesn't appear to have it.

  10. #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.

  11. #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

  12. #12
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Umeň, Sweden
    Posts
    555
    It's a POSIX function.

  13. #13
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

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

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