-1

I need be able to check the name of a folder inside a folder on a computer on the network and then if it is named one way set my buttons accordingly. so for instance i have 2 buttons one says training and one says production and all they do is rename the folder on the computers on the network to the right name so for training its DEV and for production its DEVx. So when the app loads i want it to disable the button for the one thats currently set at. So if the folder is named DEV then it disables the training button and if its DEVx it disables the production button.

This is what i have so far All code is 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

So I have it saving its current state each time the button is loaded and setting the other button to be disabled but because other users will be using this system as well it would be better for it to just set what button is disabled based on the current state of folder name.

  • [Directory.GetDirectories()](http://msdn.microsoft.com/en-us/library/c1sez4sc%28v=vs.110%29.aspx)? – TyCobb Dec 13 '14 at 01:20

1 Answers1

0

You can check to see if "\amti-0321\c$\temp\DEV" exists with Directory.Exists or Directory.GetDirectories, and set the button status appropriately.

This is probably not the best way to determine the training or production status, however, because it assumes only one set of directories exists. Also, it would be nice to use something other than string constants for the path.

xpda
  • 15,585
  • 8
  • 51
  • 82
  • Well there is only ever going to be one folder in there or rather should only ever be one folder. The application that this is switching only checks to see if the training folder exists as DEV and if so sets the servers it pulls from to the training servers so it could be renamed anything and it will then use the production servers – Kass Eisenmenger Dec 13 '14 at 03:29