Click to See Complete Forum and Search --> : Generation of unique filename
KellyLynch
February 5th, 2007, 04:03 AM
I need an algorithm to generate unique file name. I cannot use standard Win32 function GetTempFileName because of it allows create not more than 65536 filenames with the given prefix. I the limit need much more than 65536.
Thanks in advance
Krishnaa
February 5th, 2007, 04:14 AM
Is that limit documented anywhere?
humptydumpty
February 5th, 2007, 04:18 AM
Take any of the File name and add a int value to your File name . Store the int value Somewhere in Registry and When Ever you create a new File read the registry Pick Old int value from registry increment the counter and concanate it with your File name .noe Replace old int value to new one and write it back to your registry.
Filename = Filename + some int value;
now always increment the value and write new name to registry
Thanx
Krishnaa
February 5th, 2007, 04:28 AM
Take any of the File name and add a int value to your File name . Store the int value Somewhere in Registry and When Ever you create a new File read the registry Pick Old int value from registry increment the counter and concanate it with your File name .noe Replace old int value to new one and write it back to your registry.
Filename = Filename + some int value;
now always increment the value and write new name to registry
Thanx
And that will create an unique name? Have you thought of other application who can by chance create same name you might use next?
humptydumpty
February 5th, 2007, 04:33 AM
And that will create an unique name? Have you thought of other application who can by chance create same name you might use next?
That is the Concept Behind Creating a new File name everytime have a loo for Microsoft word Example and it's good if you Check Word how it created new names always.apart from this no comment
Thanx
Krishnaa
February 5th, 2007, 04:41 AM
That is the Concept Behind Creating a new File name everytime have a loo for Microsoft word Example and it's good if you Check Word how it created new names always.apart from this no comment
Thanx
Well, that not the complete logic, there is more which checks for existance of file and then again increment/something untill it gets unique name. And yes, its not needed to involve registry there, very easily you can take current timestamp, and start hitting for unique names.
humptydumpty
February 5th, 2007, 04:49 AM
i think you should keep track of the counter it's my openion .otherwise you have to do a lots of work to get the File Counter name . Remaining is upto you how you are going to implement .that's what i think .you can utilize some other technique it's not compelsory that be both will go with same logic.
Thanx
KellyLynch
February 5th, 2007, 09:50 AM
Is that limit documented anywhere?
It is obvious from description of the function. It creates filename of the following type:
<pre><uuuu>.TMP
where <uuuu> is hexadecimal value. Thus, largest possible number is 65536.
krmed
February 6th, 2007, 10:05 AM
It is obvious from description of the function. It creates filename of the following type:
<pre><uuuu>.TMP
where <uuuu> is hexadecimal value. Thus, largest possible number is 65536.
According to the MSDN documentation (http://msdn2.microsoft.com/en-us/library/aa364991.aspx), uuuu is the hexadecimal representation of uUnique, which is a UINT. Thus I believe you'll find that the maximum value is 0xFFFFFFFF or 4294967295. It's probably a shortened representation in the hex format (not always 8 characters).
Hope that helps.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.