有什么更好的方法来生成文件名的唯一值 [英] What's a better way to use for generating unique values for filenames

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

问题描述

我的团队正在支持执行多个文件处理的系统.基本上,它从某处获取数据,并将其保存在文件中,然后传输到另一个系统.当前,它使用日期/时间戳作为文件名.它的问题是,当有许多文件要处理时,某些文件将获得相同的文件名.似乎我们真的不能依赖时间戳,即使我们在上面加上了毫秒也是如此.我正在考虑使用GUID生成文件名,以确保它们将是唯一的.我的问题是,您会推荐比使用GUID更好的方法,还是我应该采用这种方法?

My team is supporting a system that does multiple file processing. Basically, it gets the data from somewhere, and saves it in a file, and is then transmitted to another system. Currently, it is using Date/Time stamp for the filenames. The problem with it is that, when there are many files to be processed, some files get the same filename. It seems that we really can''t rely on the timestamps, even if we have included milliseconds on it. I am thinking of using GUID for the generation of filenames, to ensure they will be unique. My question would be, is there a better way you would recommend than to use GUID or shall I push through with this approach?

推荐答案

两者:带有GUID的日期戳:
I would be tempted to go with both: a date stamp with a GUID attached:
20110727-cdd0d9b6-2e29-41d0-b1f7-dd38f87971b7

多余的字符应该不会引起问题,但是它们确实使搜索变得更容易...

The extra characters shouldn''t cause a problem, but they do make it easier to search...


我一直都喜欢
I have always gone with the
string filename = System.Guid.NewGuid().ToString();


方法-我通常也使用这种方法创建目录,因为清理时间要快得多,因为您可以删除整个目录而不是单个文件


approach - I usually also create directories using this approach too as the clean up time is a lot quicker as you can delete a whole directory rather than individual files


Guid.NewGuid()通常是最好的,SQL FileStream使用此方法存储其文件
Guid.NewGuid() is generally best, SQL FileStream uses this method for storing it''s files


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

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