如何将日期时间选择器值与某些文件夹名称进行比较
我的文件夹路径中有一个备份文件,如下所示 C:\Folder
文件如下图所示
文件名像这样...20111011 表示今天日期 095523 表示时间
,我有一个日期时间选择器,当用户在日期时间选择器中选择值并选择按钮时,我有按钮,
我需要将日期时间选择器值与存储在该文件夹中的文件名进行比较,然后如果日期时间选择器值与文件夹名称的部分相匹配(backup-{this is part})
我想将zip文件提取到给定文件夹中....
我怎样才能将日期时间选择器值与文件夹名称和将文件解压到给定路径....
I have a backup files in folder path is like this C:\Folder
the files are like this in below image
the file name like this...20111011 means today date
095523 means time
and i have a date time picker and i have button when the user select the value in datetime picker and select the button ,
I need to compare the date time picker value with the file name stored in that folder , and then if date time picker value matches the part of the folder name (backup-{this is part})
i want to extract zip file into the given folder ....
how can i get compare date time picker value with the folder name and extract the files in to given path ....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在.net Directory.GetFiles 方法中,用于从特定位置获取文件小路。
下面链接中提到的代码根据需要在 foreach 循环中进行更改。这个循环给你文件名,你可以比较它。
检查此链接以获取 datetimepicker 值
In .net Directory.GetFiles method used to get files from specific path.
Below code mentioned in link make changes in foreach loop as you need. This loop give you filename and you can compare it.
Check this link for datetimepicker value
您可以使用 System.IO.File
阅读完它们后,您可以使用 DateTime.ParseExact 到解析文件日期和时间。
然后您只需将文件日期和时间与日期选择器的值进行比较即可。
You can read the file names using System.IO.File
When you have read them, you can extract their dates using DateTime.ParseExact to parse the file date and time.
And then you just have to compare the file date and time with the value of your date picker.
您可以尝试这样的操作:
然后您可以使用 Emaad 的答案来处理该文件。
You can try something like this:
Then you can use the answer from Emaad to get work with the file.
只是有点“hacky”——但它确实有效。
Just a it "hacky" - but it works.
首先,您必须设置 DateTimePicker正确的日期时间格式以便选择日期和时间。
接下来我认为您必须使用 DateTimePicker.Value 构造文件名。请查看此处 ,您可以将 DateTime ToString 转换为您所需的格式。
例如...
不确定您的时间格式。如果是 12 小时则使用“H”,如果是 24 小时则使用“HH”。请参阅此处了解更多示例。剩下的就不难了...
First of all, you will have to set the DateTimePicker date-time format properly in order to select both date and time.
Next I think you have to construct the file name by using the DateTimePicker.Value. Look at here, you can ToString the DateTime to your required format.
For example...
Not sure about your time format. If it is 12 hour use "H" and use "HH" for 24 hours. Look at here for more examples. The rest won't be difficult...