Article View: borland.public.cppbuilder.nativeapi
Article #16341File time problems, anyone have any ideas?
From: Ed Mulroy [TeamB]
Date: Fri, 16 May 2003 21:59
Date: Fri, 16 May 2003 21:59
155 lines
5507 bytes
5507 bytes
Has anyone had seen this problem?
My program seems to work right, but it seems that I am not
capable of writing a file's time to the screen correctly in a
simple, console mode program.
I got the time stamps for a file with a FindNextFile and reported
them to the screen both as the time reported and as local time.
None of the time tags are right. The last write local time seems
to be the actual time I ran the test, not the file's time.
Here is what the program reported:
-----------------
May 16, 2003 21:17 test.txt creation time
May 16, 2003 4:00 test.txt last access time
May 16, 2003 21:18 test.txt last write time
May 16, 2003 17:17 test.txt creation local time
May 16, 2003 0:00 test.txt last access local time
May 16, 2003 17:18 test.txt last write local time
-----------------
A directory on the file showed this:
05/16/2003 05:08 PM 18,157 test.txt
I know that the time tags somehow translate to 5:08 PM/17:08
because the program time stamps a new file which it creates with
the values from the old one and the new file's time stamp is also
17:08.
The 4PM universal and midnight local time for last access may
be from FAT32 systems not logging all the times that NTFS logs.
This is with XP Pro, FAT32, BCB6.
The code I used follows.
-----------------
const char *month_name[12] =
{
{ "Jan" }, { "Feb" }, { "Mar" },
{ "Apr" }, { "May" }, { "Jun" },
{ "Jul" }, { "Aug" }, { "Sep" },
{ "Oct" }, { "Nov" }, { "Dec" }
};
static void ShowTime(const char *s, const FILETIME ft)
{
SYSTEMTIME st;
FileTimeToSystemTime(&ft, &st);
std::printf("%s %2d, %4d %2d:%02d %s\n",
month_name[st.wMonth - 1],
st.wDay,
st.wYear,
st.wHour,
st.wSecond,
s);
}
static void ShowLocalTime(const char *s, const FILETIME& ft)
{
FILETIME ft2;
FileTimeToLocalFileTime(&ft, &ft2);
ShowTime(s, ft2);
}
static void ReportTimes(const WIN32_FIND_DATA& wfd)
{
char temp[1024];
wsprintf(temp, "%s creation time", wfd.cFileName);
ShowTime(temp, wfd.ftCreationTime);
wsprintf(temp, "%s last access time", wfd.cFileName);
ShowTime(temp, wfd.ftLastAccessTime);
wsprintf(temp, "%s last write time", wfd.cFileName);
ShowTime(temp, wfd.ftLastWriteTime);
wsprintf(temp, "%s creation local time", wfd.cFileName);
ShowLocalTime(temp, wfd.ftCreationTime);
wsprintf(temp, "%s last access local time", wfd.cFileName);
ShowLocalTime(temp, wfd.ftLastAccessTime);
wsprintf(temp, "%s last write local time", wfd.cFileName);
ShowLocalTime(temp, wfd.ftLastWriteTime);
}
-----------------
Here is the code to get the time tags and call the function:
-----------------
static int Process(const WIN32_FIND_DATA wfd)
{
HANDLE sys_hand;
// symptoms are unchanged if I move this
// call to before the push_back line in main
ReportTimes(wfd);
// make a new file using data from the old file
// end with setting the new file's time tags to
// be the same as those of the old file
SetFileTime(sys_hand,
&wfd.ftCreationTime,
&wfd.ftLastAccessTime,
&wfd.ftLastWriteTime);
// close files, clean up some stuff and return
}
const DWORD DONT_WANT =
FILE_ATTRIBUTE_DIRECTORY ||
FILE_ATTRIBUTE_SYSTEM ||
FILE_ATTRIBUTE_OFFLINE ||
FILE_ATTRIBUTE_TEMPORARY ||
FILE_ATTRIBUTE_READONLY;
int main()
{
WIN32_FIND_DATA wfd;
HANDLE find_hand;
find_hand = FindFirstFile("*.txt", &wfd);
if (find_hand != INVALID_HANDLE_VALUE)
{
std::vector<WIN32_FIND_DATA> wfd_vec;
do
{
if (wfd.dwFileAttributes & DONT_WANT)
{
std::printf("Skipped: %s\n", wfd.cFileName);
}
else
{
wfd_vec.push_back(wfd);
}
} while (FindNextFile(find_hand, &wfd));
FindClose(find_hand);
std::for_each(wfd_vec.begin(), wfd_vec.end(), Process);
}
-----------------
. Ed
Technical Details
Message-ID:
<3ec55f4f$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,bcd78c7fec4f306a,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-05-16 15:41:27 PST From: "Ed Mulroy [TeamB]" <ed@mulroyREMOVETHESECHARS.org> Newsgroups: borland.public.cppbuilder.nativeapi Subject: File time problems, anyone have any ideas? Date: Fri, 16 May 2003 17:59:17 -0400 Lines: 157 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 24.74.175.102 Message-ID: <3ec55f4f$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1053122383 24.74.175.102 (16 May 2003 14:59:43 -0700) X-Authenticated-User: edmulroy Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail