Thread: [Dev-C++] Time stamping an output file.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Benjamin W. <ben...@ho...> - 2002-02-25 17:25:58
|
<html><div style='background-color:'><DIV></DIV> <DIV></DIV> <P>Good afternoon,</P> <P>Quick question that is probably much easier than I'm thinking it is...</P> <P>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)...<BR><BR>For example:<BR> -output file name = hsloan.txt<BR> -would like output file name = hsloanYYYYMMDD.txt<BR> (where YYYYMMDD = (year)(month)(date) of course)<BR><BR>Keep in mind that I'm using: fopen( "C:\\temp\\hsloan.txt", "w" ) ;</P> <P>Any thoughts/suggestions?</P> <P>P.S. -- Ioannis, can I cash in some of those EuroCents now?</P> <DIV></DIV> <DIV><FONT face="Geneva, Arial, Sans-serif" size=2>Benjamin Wheeless</FONT></DIV> <DIV></DIV> <DIV><FONT face="Geneva, Arial, Sans-serif" size=2><STRONG>Network Systems - Delta Airlines, Inc.</STRONG></FONT></DIV> <DIV></DIV> <DIV><FONT face=Arial size=2><STRONG>Atlanta, GA - USA 30320</STRONG></FONT></DIV> <DIV></DIV> <DIV><FONT face=Arial size=2><STRONG>==============================</STRONG></FONT></DIV> <DIV></DIV> <DIV></DIV></div><br clear=all><hr>MSN Photos is the easiest way to share and print your photos: <a href='http://go.msn.com/bql/hmtag3_etl_EN.asp'>Click Here</a><br></html> |
|
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
|
|
From: Ioannis V. <no...@ya...> - 2002-02-25 19:18:53
|
I am sorry obviously i did not understand the question. I thought you
wanted to manipulate the date/time stamp of the files, but you wanted to
put a string to the filename. You can use the functions ctime() and
time() of time.h in the style:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int main(void)
{
char filename[]="some filename - ";
time_t tp=time(NULL);
char *s=ctime(&tp);
char *newname=malloc(strlen(filename)+strlen(s)+1);
if(!newname)
return EXIT_FAILURE;
strcpy(newname, filename);
strcat(newname, s);
puts(newname);
return 0;
}
Keep in mind that this operation is portable, that is it works
everywhere.
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 Ioannis
Vranos
Sent: Monday, February 25, 2002 8:42 PM
To: Dev-C++
Subject: RE: [Dev-C++] Time stamping an output file.
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);
[ Useless things ]
|
|
From: Jason H. <jas...@bt...> - 2002-02-25 18:55:42
|
If you want to obtain the date in a way that is standard to C or C++ =
then you can use the functions supplied in the <time.h> header. I leave =
it to you to look at what it supplies in whatever C reference material =
you have (I'm too tired).
Jason.
----- Original Message -----=20
From: Benjamin Wheeless=20
To: dev...@so...=20
Sent: Monday, February 25, 2002 5:25 PM
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 =3D hsloan.txt
-would like output file name =3D hsloanYYYYMMDD.txt
(where YYYYMMDD =3D (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
=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
-------------------------------------------------------------------------=
-----
MSN Photos is the easiest way to share and print your photos: Click =
Here
_______________________________________________ Dev-cpp-users mailing =
list Dev...@li... =
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|