Vb.net 复制目录不工作
我试图使用以下代码将一个目录复制到另一个目录中,但由于某些原因,它只是复制目录的内容,而不是目录本身Vb.net 复制目录不工作,vb.net,vb.net-2010,Vb.net,Vb.net 2010,我试图使用以下代码将一个目录复制到另一个目录中,但由于某些原因,它只是复制目录的内容,而不是目录本身 Try My.Computer.FileSystem.CopyDirectory(TextBox1.Text, My.Settings.FSXLocation & "\SimObjects\Airplanes", True) MsgBox("Your 737-800 Aircraft has now been Installed.", Ms
Try
My.Computer.FileSystem.CopyDirectory(TextBox1.Text, My.Settings.FSXLocation & "\SimObjects\Airplanes", True)
MsgBox("Your 737-800 Aircraft has now been Installed.", MsgBoxStyle.Information, "Figerty Systems Inc")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Figerty Systems Inc.")
End Try
有人有什么想法吗
编辑-更多代码:
Try
Dim arg = String.Format("{0} {1} /i/y/s/e/D", Path.GetFullPath(TextBox1.Text), Path.GetFullPath(My.Settings.FSXLocation & "\SimObjects\Airplanes"))
Dim p = New Process()
p.StartInfo = New ProcessStartInfo() With { _
Key .FileName = "xcopy", _
Key .Arguments = arg, _
Key .UseShellExecute = False, _
Key .RedirectStandardOutput = True _
}
p.Start()
Console.WriteLine(p.StandardOutput.ReadToEnd())
p.WaitForExit()
Catch ex As Exception
Console.WriteLine("[FAIL] COPY: {0}", ex.Message)
Throw
End Try
Windows API不支持递归复制目录。 我只是向您展示csharp代码:
try {
var arg = string.Format("{0} {1} /i/y/s/e/D", Path.GetFullPath("../www"), Path.GetFullPath("./EM/www"));
var p = new Process();
p.StartInfo = new ProcessStartInfo {
FileName = @"xcopy",
Arguments = arg,
UseShellExecute = false,
RedirectStandardOutput = true
};
p.Start();
Console.WriteLine(p.StandardOutput.ReadToEnd());
p.WaitForExit();
} catch (Exception ex) {
Console.WriteLine("[FAIL] COPY: {0}", ex.Message);
throw;
}
愿它能帮上忙。看一看。它已经为您实现了。但是如果你真的想重新发明轮子,如果我是你,我会研究递归 这是我第一次编写vb.net代码 导入System.IO
谢谢你。我已将该代码转换为Visual Basic,但遇到一个错误,即第一个键必须以“.”开头。Hi@nomcast我在一个新的答案中发布了该代码,因为我无法将其发布到此处。此外,xcopy建议也可以,但它看起来几乎像是滥用Process.start。我会保留进程。启动用于任务,例如在进程被终止后重新启动进程,或者启动您已经编写或正在使用的另一个应用程序。它看起来与C++社区中的系统滥用非常相似。
Module Module1
Sub Main()
Try
Dim arg = String.Format("{0} {1} /i/y/s/e/D", Path.GetFullPath("src"), Path.GetFullPath("dest"))
Dim p = New Process()
p.StartInfo = New ProcessStartInfo() With {
.FileName = "xcopy",
.Arguments = arg,
.UseShellExecute = False,
.RedirectStandardOutput = True
}
p.Start()
Console.WriteLine(p.StandardOutput.ReadToEnd())
p.WaitForExit()
Catch ex As Exception
Console.WriteLine("[FAIL] COPY: {0}", ex.Message)
Throw
End Try
End Sub
End Module