首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >检查是否存在目录,是否使用路径替换变量?

检查是否存在目录,是否使用路径替换变量?
EN

Stack Overflow用户
提问于 2015-01-17 21:44:18
回答 1查看 1.7K关注 0票数 0

我正在制作一个程序/安装程序,我需要检查一个目录是否存在于- C:\Users\%USERNAME%\Appdata下面,等等。两%不起作用,我想那只是批量的。所以我尝试了另一种方法

编辑!!

所以我修改了我的代码,仍然有一个错误,这一次你可以看到我所有的代码,我知道它是高效的。谢谢!

公共类Form1

代码语言:javascript
复制
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

端级

EN

回答 1

Stack Overflow用户

发布于 2015-01-17 22:04:07

正如我在上面的注释中所述,您正在检查的目录是错误的,因为它包含了目录名的无效字符.

代码语言:javascript
复制
 '**.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

编辑i没有意识到开始阶段,是的,这是一个有效的路径。我只是在创建的文件夹中再次测试了这一点,就像您所拥有的一样,它运行得很好。不知道你还发生了什么?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28004667

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档