唯一名称生成 [英] Unique Name Generation

查看:64
本文介绍了唯一名称生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够为文件生成唯一的名称。我正在考虑使用哈希算法,但是如果我有两个同名文件,我会得到相同哈希的
。我正在收集和存储文件,我想将它们存储在同一目录中,并且我希望这些名称具有神秘性和独特性。

有什么想法吗?

Jerry

I need to be able to generate unique names for files. I was considering
that hash alogorithms, but if I had two files with the same name, I''d get
the same hash. I am collecting and storing files and I want to store them
all in the same directory and I want the names to be cryptic and unique.
Any thoughts?

Jerry

推荐答案

Jerry Camel写道:
Jerry Camel wrote:
我需要能够生成文件的唯一名称。我是在考虑哈希算法,但如果我有两个同名的文件,我会得到相同的哈希值。我正在收集和存储文件
我希望将它们存储在同一目录中,我希望
名称具有神秘性和独特性。有什么想法吗?
I need to be able to generate unique names for files. I was
considering that hash alogorithms, but if I had two files with the
same name, I''d get the same hash. I am collecting and storing files
and I want to store them all in the same directory and I want the
names to be cryptic and unique. Any thoughts?




我需要在VB3 / 8.3时代进行图像采集程序。

有可能有很多在任何给定的

天,来自许多计算机的图像,所以我想出了类似这样的base-36命名系统。 BTW,

它已经很久以前所以请不要因为数学错误而惹火。 < g>


基本36代码:

0 = 0

1 = 1

....

9 = 9

A = 10

B = 11

......

Z = 36

8.3文件名的8部分是这种形式:

YMDZZXXX

Y - 年。 0 = 1990,1 = 1991,...,Z =(1990 + 36)

M - 月。 1 = 1月1日,2月= 2月,...(基于1 - 便于阅读)

D - 第1天= 1,...(基于1 - 便于阅读) />
ZZ - 指定的计算机编号 36 * 36种可能性

XXX - 序列#。 36 * 36 * 36种可能性


该程序在ini文件中查找当天的下一个序列#

生成了8.3文件名的8部分,检查目录,如果已经

存在增量&再次尝试,反复直到ZZZ + 1失败,

保存完整的8.3(JPG,TIF,WSQ或BMP),更新了ini文件。


它运作良好。在1990年代中期拍摄的图像仍然是

指纹生物识别测试数据库的一部分,我相信。


我认为它会满足你的需求。神秘而独特的要求。 < g>


- Mark



I needed to do this in the VB3 / 8.3 era for an image capture program.
There was the possibility of many images from many computers on any given
day, so I came up with a base-36 naming system something like this. BTW,
it''s been a long time ago so please don''t flame for math errors. <g>

Base 36 code:
0 = 0
1 = 1
....
9 = 9
A = 10
B = 11
....
Z = 36

The 8 part of the 8.3 filenames were of this form:
YMDZZXXX

Y -- Year. 0 = 1990, 1=1991, ..., Z = (1990 + 36)
M -- Month. 1 = Jan, 2 = Feb, ... (1-based for ease of reading)
D -- Day 1 = 1, ... (1-based for ease of reading)
ZZ -- "Assigned Computer Number" 36 * 36 possibilities
XXX -- Sequence #. 36 * 36 * 36 possibilities

The program looked in an ini file for the next sequence # for that day,
generated the 8 part of the 8.3 filename, checked the directory, if already
existed incremened & tried again, repeatedly until ZZZ+1 before failing,
saved the full 8.3 (JPG, TIF, WSQ or BMP), updated the ini file.

It worked well. Images captured in the mid 1990''s are still part of a
fingerprint biometric test database, I believe.

I think it would satisfy your "cryptic and unique" requirements. <g>

-- Mark


Mark Jerde写道:
Mark Jerde wrote:
顺便说一句,这是很久以前所以请不要因为数学错误而惹火。 < g取代;


或者程序员内存错误要么...... ;-)我现在回忆起它有点儿了,但是b $ b更加神秘。我使用前7个字符来定义家庭字符。的文件,所有

在相同的注册中。第八个字符指定了哪个图像和

印象,即Face,Right Profile#2。或右手食指,第三次

印象。第八个字符代表的内容保存在一个ini文件中

命名为前7个字符.TXT。

8.3文件名的8个部分是这种形式的:
YMDZZXXX
BTW, it''s been a long time ago so please don''t flame for math
errors. <g>
Or programmer memory errors either... ;-) I recall now it was a little
more cryptic. I used the first 7 chars to define a "family" of files, all
in the same "enrollment." The eighth character specified which image and
impression, ie "Face, Right Profile #2" or "Right Index Finger, 3rd
impression." What the eighth character stood for was saved in a ini file
named the first 7 chars .TXT.
The 8 part of the 8.3 filenames were of this form:
YMDZZXXX




差不多。应该是

YMDZZXXA

XX - 序列#。 36 * 36种可能性

A - 哪个图像代号。 36个可能性。保存在

的家庭中.TXT文件。


FWIW ...< G>


- Mark


" Jerry Camel" < RL ***** @ msn.com>写在

新闻:eM ************* @ tk2msftngp13.phx.gbl:
"Jerry Camel" <rl*****@msn.com> wrote in
news:eM*************@tk2msftngp13.phx.gbl:
我需要能够生成文件的唯一名称。
I need to be able to generate unique names for files.




使用GUID。它们保证是独一无二的,而且它们是神秘的。生成GUID的最简单方法是从$ / b $ b请求WinAPI中的一个:


--clip--

私有类型GUID

Data1 As Long

Data2 As Integer

Data3 As Integer

Data4(7)As Byte

结束类型


私有声明功能CoCreateGuid Lib" OLE32.DLL" _

(pGuid作为GUID)长期


私函数GetGUID()字符串

Dim udtGUID作为GUID


如果(CoCreateGuid(udtGUID)= 0)那么

GetGUID = _

字符串(8 - Len(Hex



Use GUIDs. They are guaranteed to be unique, and they
are cryptic. Easiest way to generate a GUID is to
ask for one from WinAPI:

--clip--
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type

Private Declare Function CoCreateGuid Lib "OLE32.DLL" _
(pGuid As GUID) As Long

Private Function GetGUID() As String
Dim udtGUID As GUID

If (CoCreateGuid(udtGUID) = 0) Then
GetGUID = _
String(8 - Len(Hex


这篇关于唯一名称生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆