![]() |
| | #1 |
| Fountain of knowledge. Join Date: May 2006
Posts: 662
| File creation date (in windows 98 and XP) Also can you find the size of a file in a similar fashion? |
| esbo is offline | |
| | #2 |
| Mad 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 | |
| | #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 | |
| | #4 |
| Mad 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 | |
| | #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 | |
| | #6 |
| and the hat of Jobseeking 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 |
| Salem is offline | |
| | #7 |
| Mad 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 | |
| | #8 | |
| Fountain of knowledge. Join Date: May 2006
Posts: 662
| Quote:
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 | |
| | #9 |
| Fountain of knowledge. Join Date: May 2006
Posts: 662
| GCC doesn't appear to have it. |
| esbo is offline | |
| | #10 |
| Mad 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 | |
| | #11 | |
| Registered User 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:
| |
| 00Sven is offline | |
| | #12 |
| Mad Join Date: Jan 2005 Location: Umeå, Sweden
Posts: 555
| It's a POSIX function. |
| OnionKnight is offline | |
| | #13 |
| Frequently Quite Prolix 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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |