oostwijk
asked on
changing date of file
Hi there,
Can someone help me out ?
I want to make a script which modifies the date of a certain file on the server. Can someone tell me the command to modify the date ?
Can someone help me out ?
I want to make a script which modifies the date of a certain file on the server. Can someone tell me the command to modify the date ?
ASKER
ok, that's on thing, but by using this the script doesn't know what date it should get..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
#include <time.h>
#include <sys/types.h>
#include <utime.h>
#include <errno.h>
int main(int argc, char **argv)
{
int date = 21;
int month = 10;
int year = 2001;
char *filename = "name_of_file";
time_t t;
struct tm mktimeb;
struct utimbuf utimeb;
if(argc == 2) filename = argv[1];
mktimeb.tm_sec = 0;
mktimeb.tm_min = 0;
mktimeb.tm_hour = 0;
mktimeb.tm_mday = date;
mktimeb.tm_mon = month - 1;
mktimeb.tm_year = year - 1900;
mktimeb.tm_isdst = -1;
t = mktime(&mktimeb);
// utimeb.actime = t; /* access time */
utimeb.modtime = t; /* modification time */
if( utime(filename, &utimeb) )
switch(errno)
{
case (EACCES):
printf("Write to file \'%s\' is denied", filename);
case (ENOENT):
printf("File \'%s\' does not exist", filename);
exit(1);
}
exit (0);
}
#include <sys/types.h>
#include <utime.h>
#include <errno.h>
int main(int argc, char **argv)
{
int date = 21;
int month = 10;
int year = 2001;
char *filename = "name_of_file";
time_t t;
struct tm mktimeb;
struct utimbuf utimeb;
if(argc == 2) filename = argv[1];
mktimeb.tm_sec = 0;
mktimeb.tm_min = 0;
mktimeb.tm_hour = 0;
mktimeb.tm_mday = date;
mktimeb.tm_mon = month - 1;
mktimeb.tm_year = year - 1900;
mktimeb.tm_isdst = -1;
t = mktime(&mktimeb);
// utimeb.actime = t; /* access time */
utimeb.modtime = t; /* modification time */
if( utime(filename, &utimeb) )
switch(errno)
{
case (EACCES):
printf("Write to file \'%s\' is denied", filename);
case (ENOENT):
printf("File \'%s\' does not exist", filename);
exit(1);
}
exit (0);
}
ASKER
Well done, keep up the good work
$filename="/tmp/thisfile.h
`touch $filename`;