You are here:

C/Rename according to time

Advertisement


Question
hi 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

Answer
Hi 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

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise


I'm sure that I can solve any doubts in Turbo C ,Graphics Programing ,Mouse, Hardware Programming ,File System ,Interrupts, BIOS handling , TSR Programming , General Concepts in C Language, handling inline Assembly statements

Experience

Research over 6+ Years

Organizations
CG-VAK Softwares and Exports Limited

Education/Credentials
Masters in Computer Applications

©2012 About.com, a part of The New York Times Company. All rights reserved.