我需要能够检查网络上计算机上文件夹内的文件夹名称,然后如果以一种方式命名,则相应地设置我的按钮。所以例如我有2个按钮,一个说训练,一个说生产,他们所做的就是将网络上的计算机上的文件夹重命名为正确的名称,以便训练其DEV和生产它的DEVx。因此,当应用程序加载时,我希望它禁用当前设置的按钮。因此,如果该文件夹名为DEV,则会禁用训练按钮,如果其DEVx,则禁用生产按钮。
这是我到目前为止所拥有的 所有代码都是Visual Basic
Public Class Form1
Private Sub SetTraining227_Click(sender As Object, e As EventArgs) Handles SetTraining227.Click
My.Computer.FileSystem.RenameDirectory("\\amti-0321\c$\temp\DEVx", "DEV")
My.Computer.FileSystem.RenameDirectory("\\amti-0448\c$\temp\DEVx", "DEV")
My.Computer.FileSystem.RenameDirectory("\\amti-0207\c$\temp\DEVx", "DEV")
My.Computer.FileSystem.RenameDirectory("\\amti-0304\c$\temp\DEVx", "DEV")
My.Computer.FileSystem.RenameDirectory("\\amti-0005\c$\temp\DEVx", "DEV")
My.Computer.FileSystem.RenameDirectory("\\amti-0227\c$\temp\DEVx", "DEV")
My.Computer.FileSystem.RenameDirectory("\\amti-0134\c$\temp\DEVx", "DEV")
My.Computer.FileSystem.RenameDirectory("\\amti-0295\c$\temp\DEVx", "DEV")
My.Computer.FileSystem.RenameDirectory("\\amti-0387\c$\temp\DEVx", "DEV")
My.Computer.FileSystem.RenameDirectory("\\amti-0210\c$\temp\DEVx", "DEV")
My.Settings.lastSet227 = "training"
My.Settings.Save()
setting227.Text = "Training"
setprod227.Enabled = True
SetTraining227.Enabled = False
End Sub
Private Sub setprod227_Click(sender As Object, e As EventArgs) Handles setprod227.Click
My.Computer.FileSystem.RenameDirectory("\\amti-0321\c$\temp\DEV", "DEVx")
My.Computer.FileSystem.RenameDirectory("\\amti-0448\c$\temp\DEV", "DEVx")
My.Computer.FileSystem.RenameDirectory("\\amti-0207\c$\temp\DEV", "DEVx")
My.Computer.FileSystem.RenameDirectory("\\amti-0304\c$\temp\DEV", "DEVx")
My.Computer.FileSystem.RenameDirectory("\\amti-0005\c$\temp\DEV", "DEVx")
My.Computer.FileSystem.RenameDirectory("\\amti-0227\c$\temp\DEV", "DEVx")
My.Computer.FileSystem.RenameDirectory("\\amti-0134\c$\temp\DEV", "DEVx")
My.Computer.FileSystem.RenameDirectory("\\amti-0295\c$\temp\DEV", "DEVx")
My.Computer.FileSystem.RenameDirectory("\\amti-0387\c$\temp\DEV", "DEVx")
My.Computer.FileSystem.RenameDirectory("\\amti-0210\c$\temp\DEV", "DEVx")
My.Settings.lastSet227 = "prod"
My.Settings.Save()
setting227.Text = "Production"
setprod227.Enabled = False
SetTraining227.Enabled = True
End Sub
Private Sub QuitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles QuitToolStripMenuItem.Click
End
End Sub
End Class
所以我每次加载按钮时都会保存当前状态并将其他按钮设置为禁用,但因为其他用户也会使用此系统,所以最好只设置基于哪个按钮被禁用在文件夹名称的当前状态。
答案 0 :(得分:0)
您可以检查{\ {1}}或Directory.Exists
是否存在“\ amti-0321 \ c $ \ temp \ DEV”,并正确设置按钮状态。
这可能不是确定培训或生产状态的最佳方法,因为它假定只存在一组目录。此外,对于路径使用除字符串常量之外的其他内容会很好。