C/Rename according to time
Expert: Prince M. Premnath - 1/28/2008
Questionhi Premnath,
im a c newbie.
i would like to rename an existing file(xxx.7z) according to time() and
localtime() and get the outcome like 0127172718.7z
(month:day:hour:min:seconds with suffix name)
i am not sure how to do this in c.
please help.
p.s:i hope run this code under xp
AnswerHi dear Sinn !!
If you take a look at the sub components of the tm structure used by localtime , asctime , gmtime you might have find all integer components as follows
struct tm {
int tm_sec; /* Seconds */
int tm_min; /* Minutes */
int tm_hour; /* Hour (0--23) */
int tm_mday; /* Day of month (1--31) */
int tm_mon; /* Month (0--11) */
int tm_year; /* Year (calendar year minus 1900) */
int tm_wday; /* Weekday (0--6; Sunday = 0) */
int tm_yday; /* Day of year (0--365) */
int tm_isdst; /* 0 if daylight savings time is not in effect) */
};
that after inquiring the contents of the function perhaps its easy to convert all the integer members to string using the builtin function itoa() that after concatenating all the resultant strings on a temporary buffer it can be used to rename your file using the function rename().
Hope this answer will sure help you out !
For support : princeatapi@yahoo.co.in
Thanks and regards!
Prince M. Premnath