在 VB.NET 中复制文件 [英] Copy files in VB.NET
问题描述
我正在尝试创建一个类似安装程序的应用程序.这是它应该做的:在 C: 中创建一个目录并将其命名为批处理.然后从文件夹中复制文件并将其移动到 C:\batch 目录.但是复制文件不起作用.
I'm trying to create an installer-like application. Here is what its supposed to do: create a directory in C: and name it batch. Then copy the files from the folder and move it to the C:\batch directory. But the copying of files doesn't work.
如果确切目录不适用于所有目录,我应该如何将确切目录放在此处?我该怎么办?如果要复制的文件来自:E:\Documents and Settings\Rew\My Documents\Visual Studio 2008\Projects\batch\batch
How am I supposed to put the exact directory in here if that exact directory does not apply to all? What do I do with it? If the file that is to be copied is from: E:\Documents and Settings\Rew\My Documents\Visual Studio 2008\Projects\batch\batch
我希望它是通用的.这样无论文件在哪里,它都可以随时随地复制它.
I want it to be universal. So that wherever the file maybe it could always copy it regardless of where it is located.
以某种方式创建目录工作.
Somehow the creating of a directory work.
Dim FileToCopy As String
Dim NewCopy As String
Try
Directory.CreateDirectory("C:\Batch")
FileToCopy = "\batch\batch\ipconfigrenew.bat"
FileToCopy = "\batch\batch\ipconfigrelease.bat"
FileToCopy = "\batch\batch\ipconfigflushdns.bat"
NewCopy = "C:\Batch"
If System.IO.File.Exists(FileToCopy) = True Then
System.IO.File.Copy(FileToCopy, NewCopy)
MsgBox("File Copied")
End If
Catch
End Try
MsgBox("Done")
推荐答案
首先,在您进行复制时 FileToCopy 中的唯一值是最后一个.我无法解析问题以找出您需要什么,但我会先这样做:
First, the only value in FileToCopy by the time you do the copy is the last one. I'm having trouble parsing the question to figure out what you need, but I would first do this:
Dim FileToCopy(3) As String
FileToCopy(0) = "\batch\batch\ipconfigrenew.bat"
FileToCopy(1) = "\batch\batch\ipconfigrelease.bat"
FileToCopy(2) = "\batch\batch\ipconfigflushdns.bat"
Dim NewCopy As String = "C:\Batch"
Dim s As String
For Each s In FileToCopy
If System.IO.File.Exists(s) = True Then
System.IO.File.Copy(s, NewCopy)
MsgBox("File Copied")
End If
Next
接下来,我将决定是否需要以更通用的方式来编写它.
Next, I would decide if I needed to write this in a more generic way.
这篇关于在 VB.NET 中复制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!