VB.NET 7zip存档名称当前日期和时间 [英] VB.NET 7zip archive name Current Date and time

查看:122
本文介绍了VB.NET 7zip存档名称当前日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何运行7zip并将存档命名为当前日期和时间,例如:11012010192708.7z?

Does anyone know how to run 7zip and name the archive the current date and time like: 11012010192708.7z?

推荐答案

您不需要运行" 7zip.您可以使用.NET的7zip库,这是围绕7-zip库的.NET包装器:
http://sevenzipsharp.codeplex.com/ [ ^ ].

另请参见此CodeProject文章:
用于7-Zip存档DLL的C#(.NET)接口 [ ^ ].

至于文件名,您可以使用任意方式命名文件.如果需要获取当前时间,可以使用System.DateTime.NowSystem.DateTime.UtcNow;请参阅:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx [ ^ ].

要使时间不多,请使用System.DateTime.ToString(string format)和适当的格式字符串.请参阅:
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx [ ^ ].

现在您拥有了所有需要的东西.

但我不建议您使用建议的格式.在大多数情况下,最好使用标准的可排序"格式,这种格式将时间格式化为按时间顺序排列的st总是与按名称"文件相同(标准字母数字顺序),这使得在文件管理器中浏览文件非常方便(请注意,您没有询问我们有关设置文件时间的信息,例如创建或最后修改时间).此格式说明符为"s",强烈建议:年月日"T" hours-minutes-seconds.

—SA
You don''t need to "run" 7zip. You can use 7zip library for .NET, which is a .NET wrapper around 7-zip library:
http://sevenzipsharp.codeplex.com/[^].

See also this CodeProject article:
C# (.NET) Interface for 7-Zip Archive DLLs[^].

As to the file name, you can name your files any way you want. If you need to get current time, you can use System.DateTime.Now or System.DateTime.UtcNow; please see:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

To make a string out of time, use System.DateTime.ToString(string format) with appropriate format string. Please see:
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx[^],
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^].

Now you have all you need.

But I would not advise you to use the format you suggested. For most purposes, it''s much better to use standard "sortable" format, which formats the time the way that ordering of stings by time is always the same as the files "by name" (standard alphanumerical order), which makes it very convenient to look through the files in the file managers (note that you did not ask us about setting file time, such as creation or last modification time). This format specifier is "s", highly recommended: Year-month-day"T"hours-minutes-seconds.

—SA


这篇关于VB.NET 7zip存档名称当前日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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