第一次尝试 VB.NET 应用程序。我正在尝试创建一个应用程序来复制应用程序的标准配置,然后为该用户自定义某些设置。我的大部分应用程序工作正常,但资源文件有问题。
因为文件的数量可能会发生变化,所以我正在为我的资源使用一个子文件夹。我将文件设置为内容并始终复制。我可以让以下代码在调试中工作,但似乎我没有正确地进行构建。
For Each strFile In Directory.GetFiles(".\Files")
If Path.GetExtension(Path.GetFileName(strFile)) = ".vbs" Then
strDestination = strDataPath & "Scripts\"
Else
strDestination = strDataPath
End If
If Not Directory.Exists(strDestination) Then
Directory.CreateDirectory(strDestination)
End If
If My.Settings.chkForceOverwrite = True Then
Try
File.Copy(strFile, strDestination & Path.GetFileName(strFile), True)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Else
Try
File.Copy(strFile, strDestination & Path.GetFileName(strFile), False)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End If
Next
我尝试了几种复制数据的方法,但找不到任何兼容的方法,如下所示。
Dim strFileName As String = Path.GetFileNameWithoutExtension(strFile)
File.WriteAllBytes(strDestination & strFile, My.Resources.strFileName, True)
有人可以指出正确和正确的方向吗?目前文件类型是 1 个 .vbs 和 1 个 .exe.config 文件,但我以后可能需要添加不同的文件类型。