[英]checking a if directory exists, Concenating variable with path?
I was making a program/installer, and I needed to check if a directory exists under - C:\\Users\\%USERNAME%\\Appdata and so on. 我正在制作程序/安装程序,需要检查目录是否在-C:\\ Users \\%USERNAME%\\ Appdata下,依此类推。 The two % won't work, I guess that's only in batch.
这两个%无效,我想那只是批量的。 So I tried another way
所以我尝试了另一种方式
EDIT!! 编辑!!
So I revamped my code and still an error, this time you can see all my code, I know its in-efficient. 所以我修改了我的代码,但仍然是一个错误,这次您可以看到我的所有代码,我知道它的效率很低。 Thank you!
谢谢!
Public Class Form1
公开课表格1
Dim reflex As Boolean
Dim nodus As Boolean
Dim rinstalled As Boolean
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles install.Click
If ComboBox1.SelectedIndex = 0 Then
If reflex = True Then
Process.Start("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Reflex\installReflex.bat")
End If
End If
If ComboBox1.SelectedIndex = 1 Then
If nodus = True Then
Process.Start("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Nodus\installNodus.bat")
End If
End If
End Sub
Private Sub dlclient_Click(sender As Object, e As EventArgs) Handles dlclient.Click
If ComboBox1.SelectedIndex = 0 Then
My.Computer.Network.DownloadFile("http://download1644.mediafire.com/s111t3phtatg/bqsuh8c4f2n8w99/Reflex.jar", "C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Reflex\Reflex.jar")
My.Computer.Network.DownloadFile("http://download763.mediafire.com/93aqmg62kvqg/5jfpe65usw3tajw/Reflex.json", "C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Reflex\Reflex.json")
My.Computer.Network.DownloadFile("http://download939.mediafire.com/cr8u67j6ce3g/60ewsmp3l35e1mt/installReflex.bat", "C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Reflex\installReflex.bat")
status.ForeColor = Color.Green
status.Text = "Client Downloaded!"
End If
If ComboBox1.SelectedIndex = 1 Then
My.Computer.Network.DownloadFile("http://download903.mediafire.com/qmqiiyb1128g/6q6libdtwvgp0kt/NodusLauncher.jar", "C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Nodus\NodusLauncher.jar")
My.Computer.Network.DownloadFile("http://download1835.mediafire.com/4w9bh91tf9qg/ug7jsnj0gkxu2gp/NodusLauncher.json", "C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Nodus\NodusLauncher.json")
My.Computer.Network.DownloadFile("http://download1346.mediafire.com/ecje8cg9wdug/uqm37mk1k4qxi59/installNodus.bat", "C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Nodus\installNodus.bat")
status.ForeColor = Color.Green
status.Text = "Client Downloaded!"
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Start()
Timer2.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If ComboBox1.SelectedIndex = 0 Then
If System.IO.File.Exists("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Reflex\Reflex.jar") Then
If System.IO.File.Exists("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Reflex\Reflex.json") Then
If System.IO.File.Exists("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Reflex\installReflex.bat") Then
If My.Computer.FileSystem.DirectoryExists("C:\Users\" & SystemInformation.UserName & "\AppData\.minecraft\versions\Reflex") Then
install.Enabled = False
dlclient.Text = "Client installed"
Else
reflex = True
status.ForeColor = Color.Green
status.Text = "Client Downloaded!"
dlclient.Enabled = False
install.Enabled = True
dlclient.Text = "Client Already Downloaded"
End If
Else
My.Computer.FileSystem.DeleteFile("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Reflex\Reflex.json")
My.Computer.FileSystem.DeleteFile("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Reflex\Reflex.jar")
End If
Else
My.Computer.FileSystem.DeleteFile("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Reflex\Reflex.jar")
My.Computer.FileSystem.DeleteFile("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Reflex\installReflex.bat")
End If
Else
If System.IO.File.Exists("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Reflex\Reflex.json") Then
If System.IO.File.Exists("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Reflex\installReflex.bat") Then
My.Computer.FileSystem.DeleteFile("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Reflex\Reflex.json")
My.Computer.FileSystem.DeleteFile("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Reflex\installReflex.bat")
End If
Else
dlclient.Enabled = True
install.Enabled = False
status.ForeColor = Color.Red
status.Text = "Client not downloaded"
dlclient.Text = "Download Client"
End If
End If
End If
If ComboBox1.SelectedIndex = 1 Then
If System.IO.File.Exists("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Nodus\NodusLauncher.jar") Then
If System.IO.File.Exists("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Nodus\NodusLauncher.json") Then
If System.IO.File.Exists("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Nodus\installNodus.bat") Then
If My.Computer.FileSystem.DirectoryExists("C:\Users\" & SystemInformation.UserName & "\AppData\.minecraft\versions\NodusLauncher") Then
install.Enabled = False
dlclient.Text = "Client Installed"
status.Text = "Client Installed"
Else
nodus = True
status.ForeColor = Color.Green
status.Text = "Client Downloaded!"
dlclient.Enabled = False
install.Enabled = True
End If
Else
My.Computer.FileSystem.DeleteFile("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Nodus\NodusLauncher.json")
My.Computer.FileSystem.DeleteFile("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Nodus\NodusLauncher.jar")
End If
Else
My.Computer.FileSystem.DeleteFile("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Nodus\NodusLauncher.jar")
My.Computer.FileSystem.DeleteFile("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Nodus\installNodus.bat")
End If
Else
If System.IO.File.Exists("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Nodus\NodusLauncher.json") Then
If System.IO.File.Exists("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Nodus\installNodus.bat") Then
My.Computer.FileSystem.DeleteFile("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Nodus\NodusLauncher.json")
My.Computer.FileSystem.DeleteFile("C:\Program Files (x86)\MCHaxor\bin\clients\1.8\Nodus\installNodus.bat")
End If
Else
dlclient.Enabled = True
install.Enabled = False
status.ForeColor = Color.Red
status.Text = "Client not downloaded"
dlclient.Text = "Download Client"
End If
End If
End If
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
about.Show()
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
End Sub
End Class 末级
As stated in my comment above, your directory you are checking is wrong because it contains an invalid character for the directory name... 正如我在上面的评论中所述,您正在检查的目录是错误的,因为其中包含无效的目录名称字符...
'**.minecraft is invalid for a directory name...**
If My.Computer.FileSystem.DirectoryExists("C:\Users\" & SystemInformation.UserName & "\AppData\.minecraft") Then
status.Text = "Client Installed"
install.Enabled = False
End If
EDIT I wasn't aware of the beginning period and yes this is a valid path. 编辑我不知道开始的时期,是的,这是一个有效的路径。 I just tested this again with the created folders as you have and it works just fine.
我只是使用创建的文件夹再次进行了测试,效果很好。 Not sure what else you have going on?
不知道你还在做什么吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.