|
-
February 5th, 2007, 05:03 AM
#1
Generation of unique filename
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
-
February 5th, 2007, 05:14 AM
#2
Re: Generation of unique filename
Is that limit documented anywhere?
Regards,
Ramkrishna Pawar
-
February 5th, 2007, 05:18 AM
#3
Re: Generation of unique filename
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
-
February 5th, 2007, 05:28 AM
#4
Re: Generation of unique filename
 Originally Posted by humptydumpty
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?
Regards,
Ramkrishna Pawar
-
February 5th, 2007, 05:33 AM
#5
Re: Generation of unique filename
 Originally Posted by Krishnaa
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
-
February 5th, 2007, 05:41 AM
#6
Re: Generation of unique filename
 Originally Posted by humptydumpty
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.
Regards,
Ramkrishna Pawar
-
February 5th, 2007, 05:49 AM
#7
Re: Generation of unique filename
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
-
February 5th, 2007, 10:50 AM
#8
Re: Generation of unique filename
 Originally Posted by Krishnaa
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.
-
February 6th, 2007, 11:05 AM
#9
Re: Generation of unique filename
 Originally Posted by KellyLynch
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, 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.
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|