RE: [Dev-C++] Time stamping an output file.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ya...> - 2002-02-25 18:42:15
|
You can do it with win32 api:
Syntax
#include <io.h>
int getftime(int handle, struct ftime *ftimep);
int setftime(int handle, struct ftime *ftimep);
The file must be open for writing; an EACCES error will occur if the
file is open for read-only access.
struct ftime {
unsigned ft_tsec: 5; /* two seconds */
unsigned ft_min: 6; /* minutes */
unsigned ft_hour: 5; /* hours */
unsigned ft_day: 5; /* days */
unsigned ft_month: 4; /* months */
unsigned ft_year: 7; /* year - 1980*/
};
getftime, setftime
See also Examples Portability
Header File
io.h
Category
Input/output Routines
Syntax
#include <io.h>
int getftime(int handle, struct ftime *ftimep);
int setftime(int handle, struct ftime *ftimep);
Description
Gets and sets the file date and time.
getftime retrieves the file time and date for the disk file associated
with the open handle. The ftime structure pointed to by ftimep is filled
in with the file's time and date.
setftime sets the file date and time of the disk file associated with
the open handle to the date and time in the ftime structure pointed to
by ftimep. The file must not be written to after the setftime call or
the changed information will be lost. The file must be open for writing;
an EACCES error will occur if the file is open for read-only access.
They require the file to be open for writing; an EACCES error will occur
if the file is open for read-only access.
The ftime structure is defined as follows:
struct ftime {
unsigned ft_tsec: 5; /* two seconds */
unsigned ft_min: 6; /* minutes */
unsigned ft_hour: 5; /* hours */
unsigned ft_day: 5; /* days */
unsigned ft_month: 4; /* months */
unsigned ft_year: 7; /* year - 1980*/
};
Return Value
getftime and setftime return 0 on success.
In the event of an error return -1 is returned and the global variable
errno is set to one of the following values:
EACCES Permission denied
EBADF Bad file number
EINVFNC Invalid function number
Example:
FILE *stream;
std::ftime ft;
if ((stream = fopen("TEST.$$$",
"wt")) == NULL)
{
fprintf(stderr, "Cannot open output file.\n");
return 1;
}
getftime(fileno(stream), &ft);
printf("File time: %u:%u:%u\n",
ft.ft_hour, ft.ft_min,
ft.ft_tsec * 2);
Ioannis
* Ioannis Vranos
* Programming pages: <http://www.noicys.d2g.com/>
http://www.noicys.d2g.com
* Alternative URL: <http://run.to/noicys> http://run.to/noicys
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Benjamin
Wheeless
Sent: Monday, February 25, 2002 7:26 PM
To: dev...@so...
Subject: [Dev-C++] Time stamping an output file.
Good afternoon,
Quick question that is probably much easier than I'm thinking it is...
Does anyone out there know how to easily put a date stamp on an output
file using C rather than using the environments shell? I know how to do
it using Korn, but I'm working on WinNT and so I need the source code to
do it rather than cmd.exe(unless cmd.exe can do it easier via a batch
file or something)...
For example:
-output file name = hsloan.txt
-would like output file name = hsloanYYYYMMDD.txt
(where YYYYMMDD = (year)(month)(date) of course)
Keep in mind that I'm using: fopen( "C:\\temp\\hsloan.txt", "w" )
;
Any thoughts/suggestions?
P.S. -- Ioannis, can I cash in some of those EuroCents now?
Benjamin Wheeless
Network Systems - Delta Airlines, Inc.
Atlanta, GA - USA 30320
==============================
_____
MSN Photos is the easiest way to share and print your photos: Click
<http://go.msn.com/bql/hmtag3_etl_EN.asp> Here
_______________________________________________ Dev-cpp-users mailing
list Dev...@li...
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|