Link a textbox to a cmd command in Visual Basics
I want to make a program that will sync two folders together with the command in cmd called xcopy, so when i click on a sync logo the folders sync. But i want the user to be able to browse for the locations then set the locations as they sync folders. I already have linked two FolderBrowserDialogs to two textboxes so when i select a folder in the browser the directory shows in the text box. But then how do i put the two directories into the xcopy command? This is what i have done so far...
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FolderBrowserDialog1.ShowDialog()
TextBox1.Text = FolderBrowserDialog1.SelectedPath
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
FolderBrowserDialog2.ShowDialog()
TextBox2.Text = FolderBrowserDialog2.SelectedPath
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Shell("CMD.exe")
SendKeys.Send("xcopy C:\folder1 C:\folder2 /D /E")
SendKeys.Send("xcopy C:\folder2 C:\folder1 /D /E")
SendKeys.Send("{ENTER}")
SendKeys.Send("EXIT")
End Sub
End Class
I want the C:\folder1 to show up as whats in the TextBox1 and the c:\folder2 to show up as whats in the TextBox2.
Thanks Alot :)
PLEASE HELP!
Re: Link a textbox to a cmd command in Visual Basics
Code:
SendKeys.Send("xcopy " & TextBox1.Text & " " & TextBox2.Text & " /D /E")
SendKeys.Send("xcopy " & TextBox2.Text & " " & TextBox1.Text & " /D /E")
Also, the code you posted is VB.Net and this forum section is for VB Classic. I'll tell the mods to move the thread for you.
Re: Link a textbox to a cmd command in Visual Basics
1) SendKeys is notoriously unreliable... and less so in .NET
2) what baja posted will work... up until the first time you have a space in one of your paths.
3) There are other ways to do this in .NET... probably safer too...
-tg
Re: Link a textbox to a cmd command in Visual Basics
I agree regarding SendKeys. You should definitelly look into alternatives. My ability with .Net is limited though.
One other way would be to create a batch file instead, then execute it. You don't need real time interaction so no need to use a system like SendKeys.
Re: Link a textbox to a cmd command in Visual Basics
Thread moved from 'VB6 and Earlier' forum to 'VB.Net' (VB2002 and later) forum
(thanks for letting us know baja_yu :thumb: )
Re: Link a textbox to a cmd command in Visual Basics
If you're using VB.NET then why not use VB.NET? VB.NET can move and copy files and folders with classes from the System.IO namespace.