Touching a file (set to current time and date) 
Author Message
 Touching a file (set to current time and date)

I need to "touch" a file from within a C program.  In other words, I
need to update the time and date of the file to the current time and
date.  Is there a function that does this ?  I'm running the program
under Unix.  I know I can use a dirty trick like reading the file and
then creating a new file and writing out the same contents, but I
don't want to do that.  Also, I might be able to fopen the file with
the "a" access parameter, and then just fclose it immediately.  That
might work in general, but again, I think it might not work in this
case, because the file that I want to touch is the program itself.
So, in other words, I want to write a program that will touch itself,
no pun intended.  Any help will be greatly appreciated...

-Eric



Sun, 14 Nov 1999 03:00:00 GMT  
 Touching a file (set to current time and date)

Quote:

> I need to "touch" a file from within a C program.  In other words, I
> need to update the time and date of the file to the current time and
> date.  Is there a function that does this ?  I'm running the program
> under Unix.  I know I can use a dirty trick like reading the file and
> then creating a new file and writing out the same contents, but I
> don't want to do that.  Also, I might be able to fopen the file with
> the "a" access parameter, and then just fclose it immediately.  That
> might work in general, but again, I think it might not work in this
> case, because the file that I want to touch is the program itself.
> So, in other words, I want to write a program that will touch itself,
> no pun intended.  Any help will be greatly appreciated...

> -Eric

man utime gives :

 utime(2)                                                          
utime(2)

 NAME
      utime - set file access and modification times

 SYNOPSIS
      #include <utime.h>

      int utime(const char *path, const struct utimbuf *times);

--
Herve Couppe de Lahongrais (SEU)       | Eurocontrol Experimental Centre



Sun, 14 Nov 1999 03:00:00 GMT  
 Touching a file (set to current time and date)



Quote:

>> I need to "touch" a file from within a C program.  In other words, I
>> need to update the time and date of the file to the current time and
>> date.  Is there a function that does this ?

There is no C language function that does this, the C language doesn't define
attributes for files such as timestamps.

Quote:
>>  I'm running the program
>> under Unix.

Unix programming resources are best asked about in comp.unix.programmer.

Quote:
>man utime gives :

> utime(2)                                                          
>utime(2)

> NAME
>      utime - set file access and modification times

> SYNOPSIS
>      #include <utime.h>

>      int utime(const char *path, const struct utimbuf *times);

Be clear that this is POSIX/Unix specific. Somebody reading the newsgroup
who is not aware of Unix man conventions and formats may not realise this.
Also note that under Unix a file has three timestamp values but this only
sets two of them.

--
-----------------------------------------


-----------------------------------------



Sun, 14 Nov 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. QUESTION: How to set the time and date for a file's creation or modification

2. How to set file date/time?

3. Set Date in Date Time Picker

4. set file time & date

5. set date/time/time zone dialog

6. help-get current date using time.h

7. Question about Get Server Current Date and time, thank you

8. current date time

9. Getting the current date/time

10. current date/time format question ????

11. Displaying the current time and date in a dialog using COleDateTime

12. Get current time and date form an Server

 

 
Powered by phpBB® Forum Software