Board index » cppbuilder » Unique Filenames

Unique Filenames


2003-10-04 03:51:58 AM
cppbuilder25
How about:
String hourfile = FormatDateTime("yymmddhhnnsszzz", Now()) ;
hourfile = Path + hourfile + ".txt" ;
 
 

Re:Unique Filenames

"Elias Berelian" < XXXX@XXXXX.COM >writes:
Quote
How about:

String hourfile = FormatDateTime("yymmddhhnnsszzz", Now()) ;
hourfile = Path + hourfile + ".txt" ;
How do you _know_ that file doesn't already exist? You can't have a
guaranteed unique filename algorithm without checking what already
exists...
--
Chris (TeamB);
 

Re:Unique Filenames

"Elias Berelian" < XXXX@XXXXX.COM >wrote in message
Quote
How about:

String hourfile = FormatDateTime("yymmddhhnnsszzz", Now()) ;
hourfile = Path + hourfile + ".txt" ;
Depending if you have a really fast machine this may not work...theres not a
100% guaruntee that you won't create the 2 file names in the same
millisecond.
To be safe I'd generate a couple random numbers and append them onto the
file name as well...then you should be pretty safe that the the name will
always be unique.
 

{smallsort}

Re:Unique Filenames

"Junk Mail" < XXXX@XXXXX.COM >wrote in message
Quote
To be safe I'd generate a couple random numbers and append
them onto the file name as well...then you should be pretty safe
that the the name will always be unique.
That is still not 100% guaranteed. Like Chris said, you have to test the
filename to make sure that it doesn't really exist before you assume
anything.
Gambit