管理具有相同名称和不同内容的attachmnet文件
我正在从收件箱、发送、草稿等邮件中提取附件。 并将它们保存在文件夹中。
使用以下逻辑:
但是问题我面对的是这里。 类型和名称相同但内容不同的附件。 在当前情况下,它正在用新文件替换旧文件。
我如何能够独特地管理不同邮件的此附件。
I am extracting attachment from Inbox,Send,Drafts e.t.c. mails.
And saving them in a folder.
Using below logic:
How to Access attachments from Notes mail?
But problem i am facing here is.
Attachment having same type and name but different content.
In current situation it is replacing old file with new one.
How i can uniquely manage this attachment for different mails.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 File.Exists(path) 在提取之前验证文件是否存在,如果存在,则在名称中添加一些内容以使其唯一。
You can use the File.Exists(path) to verify if the file exists before extracting and if it does then add something to the name to make it unique.
有几种方法:
1)始终为每个附件生成一个随机文件名(这里的否定是您将使用“更多”存储空间
2)生成文件内容的哈希值(例如 SH-256),并在此之后为其命名(这里的负值是哈希值可能需要一段时间,具体取决于文件大小)
根据您所做的事情,我当然会将原始文件名保存在某处,以便可以根据电子邮件中的文件名找到它。如果您选择散列方法,也许还应该存储该文件所附加的电子邮件。
There is several ways:
1) Always generate a random filename, for every attachment ( Negative here is that you will use "more" storage space
2) Generate a hash like SH-256 of the content of the file, and give it a name after this ( Negative here is hashing can take a while, depending on file size)
Depending on what your doing, i would off course save the original filename somewhere so it can be found based on the filename in the email. Perhaps also if you choose the hashing method, you should store what emails that file is attached to.
其他一些想法:
您可以将 Notes 文档唯一 ID 添加到文件名中。然后,您还可以确定该文件来自哪个 Notes 文档。
过去,我只是按照大多数程序的处理方式来处理这个问题。我将 _x 附加到文件名,其中 x 是数字。因此,如果存在三个同名文件,它们将在文件夹中显示为 file.txt、file_1.txt、file_2.txt。
A few other ideas:
You could add the Notes Document Unique ID to the file name. Then you'd also have a way to determine which Notes Document the file came from.
In the past, I just handled this the way I see most programs handle it. I appended _x to the file name where x is a number. So if there were three files with the same name, they'd show up in the folder as file.txt, file_1.txt, file_2.txt.