"yes, I do love my .bat scripts" that aint no batch file.
you should add the tag "dotnet-visual-basic" to increase the chances of getting an answer.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I have been working on a small script to help with the setting up of users' workstations and have hit a brick wall.
What I am wanting to accomplish is that by selecting a role in the Listbox and clicking on button1 a network directory gets copied to the current user's desktop.
I am sure I am missing something easy and would greatly appreciate any and all help.
yes, I do love my .bat scripts
Please see the below code I have been working on
Imports System.Net.Mail
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' add items to the listbox
With lbDepartments
.Items.Add("Bookings")
.Items.Add("Logistics")
.Items.Add("Materials")
.Items.Add("Programming")
.Items.Add("Traffic")
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
If lbDepartments.SelectedIndex = 0 Then
My.Computer.FileSystem.CopyDirectory("O:\Common\COMPUTER_SETUPS\1-DEPARTMENTS\BOOKING SETUPS\", "desktop\setup\", True)
End If
End Sub
'If lbDepartments.SelectedIndex = 1 Then
'If bDepartments.SelectedIndex = 2 Then
'If lbDepartments.SelectedIndex = 3 Then
'If lbDepartments.SelectedIndex = 4 Then
'End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
' Change language with batch file
Shell("O:\Common\COMPUTER_SETUPS\Setup_Scripts\region.bat")
End Sub
Private Sub Button3_click(sender As Object, e As EventArgs) Handles Button3.Click
' change list seperator with batch file
Shell("O:\Common\COMPUTER_SETUPS\Setup_Scripts\list_seperator.bat")
End Sub
Private Sub Button4_click(sender As Object, e As EventArgs) Handles Button3.Click
' change region with batch file
Shell("O:\Common\COMPUTER_SETUPS\Setup_Scripts\region.bat")
End Sub
Private Sub Button5_click(sender As Object, e As EventArgs) Handles Button3.Click
' change time and date with batch file
Shell("O:\Common\COMPUTER_SETUPS\Setup_Scripts\time_and_date.bat")
End Sub
End Class
"yes, I do love my .bat scripts" that aint no batch file.
you should add the tag "dotnet-visual-basic" to increase the chances of getting an answer.
Dim s As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
If lbDepartments.SelectedIndex = 0 Then
My.Computer.FileSystem.CopyDirectory("O:\Common\COMPUTER_SETUPS\1-DEPARTMENTS\BOOKING SETUPS\", "desktop\setup\", True)
You define a variable named "s" that contains the path to the user's desktop folder, but you don't use the variable anywhere. The destination folder is "desktop\setup\" which would be relative to whatever the current working directory for the program is.
This below might be what you want, I'm not sure of your requirements. Search the file system for the files that you are copying.
My.Computer.FileSystem.CopyDirectory("O:\Common\COMPUTER_SETUPS\1-DEPARTMENTS\BOOKING SETUPS\", s & "\setup\", True)
Well, if you are running a bat file, we can't help you until you share its contents. So I assume that your question is about the CopyDirectory statement.
Add diagnostic displays to verify that you looking at the folder names that you think you are processing.
Dim strDestFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\test\"
Dim dirinfo As IO.DirectoryInfo
Console.WriteLine("The destination folder is " & strDestFolder)
If My.Computer.FileSystem.DirectoryExists(strDestFolder) Then
Console.WriteLine("The folder exists!")
dirinfo = My.Computer.FileSystem.GetDirectoryInfo(strDestFolder)
Console.WriteLine("Current file count is " & dirinfo.GetFiles.Count)
Else
Console.WriteLine("The folder does not exists!")
End If
My.Computer.FileSystem.CopyDirectory("c:\temp\tdrive\", strDestFolder, True)
dirinfo = My.Computer.FileSystem.GetDirectoryInfo(strDestFolder)
Console.WriteLine("File count is now " & dirinfo.GetFiles.Count)
Console.ReadLine()
I still cannot get the folders to copy to the desktop or even C:\Users\michael.smith\Desktop\setup
any and all help is greatly appreciated
Imports System.Net.Mail
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' add items to the listbox
With lbDepartments
.Items.Add("Bookings")
.Items.Add("Logistics")
.Items.Add("Materials")
.Items.Add("Programming")
.Items.Add("Traffic")
End With
End Sub
Private Sub Button0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Move setup files to desktop
Dim s As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
If lbDepartments.SelectedIndex = 0 Then
My.Computer.FileSystem.CopyDirectory("O:\Common\COMPUTER_SETUPS\1-DEPARTMENTS\BOOKING SETUPS\", s & "\setup\", True)
End If
'Copy Logistics files to desktop
If lbDepartments.SelectedIndex = 1 Then
My.Computer.FileSystem.CopyDirectory("O:\Common\COMPUTER_SETUPS\1-DEPARTMENTS\LOGISTICS SETUPS", s & "\setup\", True)
End If
'Copy Materials files to desktop
If lbDepartments.SelectedIndex = 2 Then
My.Computer.FileSystem.CopyDirectory("O:\Common\COMPUTER_SETUPS\1-DEPARTMENTS\MATERIALS SETUPS\", s & "\setup\", True)
End If
'Copy Programming files to desktop
If lbDepartments.SelectedIndex = 3 Then
My.Computer.FileSystem.CopyDirectory("O:\Common\COMPUTER_SETUPS\1-DEPARTMENTS\PROGRAMMING SETUPS\", s & "\setup\", True)
End If
'Copy Traffic files to desktop
If lbDepartments.SelectedIndex = 4 Then
My.Computer.FileSystem.CopyDirectory("O:\Common\COMPUTER_SETUPS\1-DEPARTMENTS\TRAFFIC SETUPS\", s & "\setup\", True)
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button2.Click
' Change language with batch file
Shell("O:\Common\COMPUTER_SETUPS\Setup_Scripts\region.bat")
End Sub
Private Sub Button2_click(sender As Object, e As EventArgs) Handles Button3.Click
' change list seperator with batch file
Shell("O:\Common\COMPUTER_SETUPS\Setup_Scripts\list_seperator.bat")
End Sub
Private Sub Button3_click(sender As Object, e As EventArgs) Handles Button3.Click
' change region with batch file
Shell("O:\Common\COMPUTER_SETUPS\Setup_Scripts\region.bat")
End Sub
Private Sub Button4_click(sender As Object, e As EventArgs) Handles Button3.Click
' change time and date with batch file
Shell("O:\Common\COMPUTER_SETUPS\Setup_Scripts\time_and_date.bat")
End Sub
End Class
I still can't seem to get it to work, sorry about all the noob questions.
I am still learning and really appreciate all the help and tips
Private Sub Button0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button0.Click
'Move setup files to desktop
Dim strDestFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\test\"
Dim dirinfo As IO.DirectoryInfo
'Move Bookings files to desktop
If lbDepartments.SelectedIndex = 0 Then
Console.WriteLine("The destination folder is " & strDestFolder)
My.Computer.FileSystem.DirectoryExists(strDestFolder)
Console.WriteLine("The folder exists!")
Else
dirinfo = My.Computer.FileSystem.GetDirectoryInfo(strDestFolder)
Console.WriteLine("Current file count is " & dirinfo.GetFiles.Count)
Console.WriteLine("The folder does not exists!")
Else
My.Computer.FileSystem.CopyDirectory("c:\temp\tdrive\", strDestFolder, True) Then
dirinfo = My.Computer.FileSystem.GetDirectoryInfo(strDestFolder)
Console.WriteLine("File count is now " & dirinfo.GetFiles.Count)
Console.ReadLine()
End If
'If lbDepartments.SelectedIndex = 0 Then
'End If
'Copy Logistics files to desktop
'If lbDepartments.SelectedIndex = 1 Then
'End If
'Copy Materials files to desktop
' If lbDepartments.SelectedIndex = 2 Then
'End If
'Copy Programming files to desktop
' If lbDepartments.SelectedIndex = 3 Then
' End If
'Copy Traffic files to desktop
' If lbDepartments.SelectedIndex = 4 Then
'End If
End Sub