Re: Creating a file with timestamp

From: Robert M. Riches Jr. (spamtrap42_at_verizon.net)
Date: 09/14/05


Date: Wed, 14 Sep 2005 04:45:33 GMT

I'll leave to someone else the netiquette lesson about it
being good to include some context to clue in people who
might not have seen the message to which you're responding.

On 2005-09-14, milkyway <d0mufasa@hotmail.com> wrote:
> At first I had thought about the possibility that everything was being
> executed in the same second. I had searched for a way to print out
> milliseconds but did not see anything ;-(
>
> Does this mean that one creates a filename with the date and time as a
> timestamp that there is no way for this (the filename) to actually be
> unique?

If you are creating a filename based on a timestamp, and the
timestamp is in coarser granularity than the minimum period
between attempts to make such a filename, then, yes, the
filenames will not be unique.

If you want them to be unique, then you could either use a
finer-grained timestamp (microseconds perhaps) or add
something to the name to make it unique. Depending on your
situation, you could use a process ID, provided the same
process wouldn't try to create multiple files (within the
timestamp granularity. Or, you could write script or C code
to add something of your choosing. For some of my sysadmin
purposes, I manually append an 'a', 'b', 'c', and so forth
to filenames whose names are based only on the date. For
other tasks, I have a shell script that chooses the lowest
three-digit number for which a file does not already exist.

Depending on your situation, it might be simplest to stuff
in a 2-second delay (anything just a little over 1 second
should actually suffice) in the right place to guarantee
that you wouldn't be creating multiple files with the same
timestamp.

Robert Riches
spamtrap42@verizon.net
(Yes, that is one of my email addresses.)



Relevant Pages

  • Re: time(NULL) returning wrong month???
    ... im writing a logging utility the log files created will contain 14byte ... are its timestamp, that is the # of seconds ... last is the date string i use to create the filename with (filename ...
    (comp.unix.programmer)
  • time(NULL) returning wrong month???
    ... im writing a logging utility the log files created will contain 14byte ... are its timestamp, that is the # of seconds ... last is the date string i use to create the filename with (filename ... GetFDate to write the filename date string. ...
    (comp.unix.programmer)
  • Re: file numbering
    ... OEX will prepend or append a timestamp to the ... filename as well to allow for sorting based on subject / date or date / ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: saveas without prompt
    ... xlLocalSessionChanges ... Excel session, ... I tend to solve such conflicts by adding a timestamp ... to the filename if the pure file name already exists. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Image storing in database
    ... >how about the syntax for multiple files? ... >but for multiple files, do I add an if statement for each filename, or ... Prev by Date: ...
    (comp.lang.php)