如何在Vb.Net应用程序中创建自动备份文件 [英] How To Create Automated Backup Files In Vb.Net Application
本文介绍了如何在Vb.Net应用程序中创建自动备份文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在30天内创建自动备份文件和备份类型压缩。
但我想备份包含数据文件的文件夹(.doc,.xls,.tiff,.pdf ... )但不是sql数据库。
谢谢。
解决方案
请看我对这个问题的评论:你的意思是怎么样?做一些工作。
您可以使用以下方法之一递归地收集某些目录中的所有文件: http://msdn.microsoft.com/en-us/library/system.io.directory。 getfiles%28v = vs.110%29.aspx [ ^ ]。
使用您的文件类型它不会是问题,但是,为了以防万一,请注意我在过去的答案中描述的一个微妙问题: Directory.Get.Files搜索模式问题 [ ^ ]。
您可以以某种方式压缩所有文件。特别是,您可以使用其中一个库对它们进行压缩。请查看我过去的答案:
比较两个文件夹 [ ^ ] ,
使用vb.net提取文件rar [ ^ ]。
另见这一篇: http://sharpcompress.codeplex.com [ ^ ]。
类似的东西。这更像是一项工作要做;没有什么特别需要一些特别的建议,但你需要自己完成这项工作。任何具体问题?还有什么其他的,快速回答可以帮助吗?
-SA
我想要文件备份SHARE-AC.zip。但现在已经获得文件夹SHARE-AC不拉链
Imports System.IO
Imports System.IO.Compression
公开 类 Form1
私有 Sub Form1_Load( ByVal sender As System。 Object , ByVal e As System.EventArgs)句柄 MyBase .Load
Dim dstr 作为 字符串
Dim mstr 作为 字符串
Dim ystr As String
Dim folstr As String
Dim dsumstr As String
dstr = DateTime.Today.ToString( dd)
mstr = DateTime.Today.ToString( MM)
ystr = DateTime.Today.ToString( yyyy)
dsumstr = ystr& - & mstr& - & dstr
folstr = Y:\\\ server1 \Fileserver - & dsumstr
尝试
My.Computer.FileSystem.CreateDirectory(folstr)
My.Computer.FileSystem.CreateDirectory( folstr& \ SHARE-AC)
My.Computer.FileSystem.CopyDirectory ( D:\ SHARE-AC,folstr& \ SHARE-AC)
Label1.Text = 备份日期& dsumstr& 完成
Catch ex As 异常
Label1.Text =(ex.Message)
结束 < span class =code-keyword>尝试
结束 Sub
私有 Sub Button1_Click( ByVal 发件人作为系统。对象, ByVal e As System.EventArgs)句柄 Button1.Click
Me .Close()
结束 Sub
结束 类跨度>
How to create automated backup files in 30 days and backup type compress.
But I want to backup the folder containing Data Files (.doc,.xls,.tiff,.pdf...) but not sql database.
Thank You.
解决方案
Please see my comment to the question: what do you mean "how"? Do some work.
You can collect all files in some directory, recursively, using, one of these methods: http://msdn.microsoft.com/en-us/library/system.io.directory.getfiles%28v=vs.110%29.aspx[^].
With your file type it won't be a problem, but, just in case, be aware of one delicate problem I described in my past answer: Directory.Get.Files search pattern problem[^].
You can compress all the files in one somehow. In particular, you can ZIP them using one of the libraries. Please see my past answers:
Compare between two folders[^],
Extract file rar with vb.net[^].
See also this one: http://sharpcompress.codeplex.com[^].
Something like that. This is more of a work to be done; there is nothing special which requires some special advice, but you need to do the job by yourself. Any specific concerns? Anything else, where a Quick Answer could help?
—SA
I Want file Backup SHARE-AC.zip. But now have get folder SHARE-AC don't zip
Imports System.IO Imports System.IO.Compression Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim dstr As String Dim mstr As String Dim ystr As String Dim folstr As String Dim dsumstr As String dstr = DateTime.Today.ToString("dd") mstr = DateTime.Today.ToString("MM") ystr = DateTime.Today.ToString("yyyy") dsumstr = ystr & "-" & mstr & "-" & dstr folstr = "Y:\server1\Fileserver-" & dsumstr Try My.Computer.FileSystem.CreateDirectory(folstr) My.Computer.FileSystem.CreateDirectory(folstr & "\SHARE-AC") My.Computer.FileSystem.CopyDirectory("D:\SHARE-AC", folstr & "\SHARE-AC") Label1.Text = "Back up DATE " & dsumstr & " Complete" Catch ex As Exception Label1.Text = (ex.Message) End Try End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Close() End Sub End Class
这篇关于如何在Vb.Net应用程序中创建自动备份文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文