-
Oct 27th, 2014, 06:27 AM
#1
Thread Starter
Lively Member
Batch command in specific folder ??
This command batch :
Code:
@Echo Off & SETLOCAL
echo
echo
echo
SET "StartFolder=."
FOR /r "%StartFolder%" %%i IN (*) DO call:doit "%%~i"
GOTO:EOF
:doit
SET "fname=%~nx1"
SETLOCAL ENABLEDELAYEDEXPANSION
SET "fsize=!$%fname%!"
IF DEFINED $!fname! (
ENDLOCAL
IF "%fsize%"=="%~z1" DEL "%~1"
) ELSE (
ENDLOCAL
SET "$%~nx1=%~z1"
)
GOTO:EOF
The command works fine with this code :
Code:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim p As New Process
p.StartInfo.FileName = "C:\Users\ALEX\Desktop\Nuova cartella\DelFile.bat"
p.StartInfo.WorkingDirectory = "C:\Users\ALEX\Desktop\Nuova cartella\ImageCount"
p.Start()
End Sub
The question that I would like, that the parameter "p.StartInfo.WorkingDirectory =" to choose from, with the function "FolderBrowserDialog ()", the directory or folder where to run "DelFile.bat" .....
Does anyone know how to do help me.
Last edited by mingolito; Oct 27th, 2014 at 06:32 AM.
-
Oct 28th, 2014, 04:23 PM
#2
Thread Starter
Lively Member
Re: Batch command in specific folder ??
The command in a specific folder I solved...
I have just one last question, I hope someone help me !!!!!
This command:
Code:
Dim zipFile As String
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles SAVE.Click
Dim id As Integer = Shell(String.Format("InstallFiles\7z.exe a -t7z -m9=LZMA2 -aoa {0} {1}", zipFile, sourceDir))
Console.WriteLine(id)
In the moment in which compression start in 7zip, I would like to appear in a Textbox and RichTextBox the contents of the command, as generated in dos, How can I do?
-
Oct 28th, 2014, 08:17 PM
#3
Re: Batch command in specific folder ??
Go to the VB.NET CodeBank forum and sort by Thread Starter. Amongst the threads started by gigemboy you will find one about Automating A Command Prompt, which shows you how to redirect the output from a console window.
-
Oct 29th, 2014, 05:11 AM
#4
Thread Starter
Lively Member
Re: Batch command in specific folder ??
Originally Posted by jmcilhinney
Go to the VB.NET CodeBank forum and sort by Thread Starter. Amongst the threads started by gigemboy you will find one about Automating A Command Prompt, which shows you how to redirect the output from a console window.
OK I read it, but I can not figure out how to integrate my command line "SHELL ...", in the method used by gigemboy to Redirect the output of the application?
Could you give me an example Thanks....
-
Oct 29th, 2014, 05:25 AM
#5
Re: Batch command in specific folder ??
Originally Posted by mingolito
OK I read it, but I can not figure out how to integrate my command line "SHELL ...", in the method used by gigemboy to Redirect the output of the application?
Could you give me an example Thanks....
You don't call Shell. You should basically never call Shell in VB.NET. You call Process.Start.
-
Oct 29th, 2014, 06:30 AM
#6
Thread Starter
Lively Member
Re: Batch command in specific folder ??
Originally Posted by jmcilhinney
You don't call Shell. You should basically never call Shell in VB.NET. You call Process.Start.
I get it but I have to change everything, and can do the same thing with SHELL.
How do I change the call Shell in ProcessStart......
Code:
Dim zipFile As String
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles SAVE.Click
Dim id As Integer = Shell(String.Format("InstallFiles\7z.exe a -t7z -m9=LZMA2 -aoa {0} {1}", zipFile, sourceDir))
Console.WriteLine(id)
so that everything works as before.
Code:
Process.Start("InstallFiles\InstallFiles\7z.exe a -t7z -m9=LZMA2 -aoa {0} {1}", BinFile1, sourceDir1), 1, True, )
ERROR.."None Start accepts this number of arguments"
-
Oct 29th, 2014, 08:45 AM
#7
Re: Batch command in specific folder ??
So what did you find when you read the documentation for Process.Start to see what arguments it does take? Don't sit and wait for information to find you. Go look for it. There's a Help menu in your IDE for a reason.
-
Oct 29th, 2014, 09:51 AM
#8
Thread Starter
Lively Member
Re: Batch command in specific folder ??
Originally Posted by jmcilhinney
So what did you find when you read the documentation for Process.Start to see what arguments it does take? Don't sit and wait for information to find you. Go look for it. There's a Help menu in your IDE for a reason.
The Process.Start can not use it I have to use force to call Shell because they are more calls ... Console.WriteLine (id1) (id2), (id3) .. etc.
I thought it was easier to bring up a DOS window in a texbox. but I know that is an impossible mission .... mha.
-
Oct 29th, 2014, 03:30 PM
#9
Thread Starter
Lively Member
Re: Batch command in specific folder ??
Ok I almost solved it this way:
Code:
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim id1 As String
id1 = "InstallFiles\7z.exe"
Dim Method1 As String
Method1 = String.Format("a -t7z -m9=LZMA2 -aoa {0} {1}", BinFile1, sourceDir1)
Console.WriteLine(id1)
Dim myProcess As New Process()
Dim myProcessStartInfo As New ProcessStartInfo(id1, Method1)
myProcessStartInfo.UseShellExecute = False
myProcessStartInfo.RedirectStandardOutput = True
myProcess.StartInfo.RedirectStandardError = True
myProcess.StartInfo = myProcessStartInfo
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized
myProcess.StartInfo.CreateNoWindow = False
myProcess.Start()
Dim myStreamReader As StreamReader = myProcess.StandardOutput
Dim sOutput As String
Using oStreamReader As System.IO.StreamReader = myProcess.StandardOutput
sOutput = oStreamReader.ReadToEnd()
RichTextBox1.Text = sOutput
End Using
myProcess.Refresh()
myProcess.Close()
End Sub
The problem that I can not display the flow of control, but only the final result.
I would like to show the flow of control during compression as it appears in the DOS window ... !!! Someone can help me on this ????
-
Oct 30th, 2014, 04:44 PM
#10
Thread Starter
Lively Member
Re: Batch command in specific folder ??
Guys anyone has any ideas, I can not see the DOS window in the RichTextBox .... !!!!!
I do not think it's a difficult thing for you .. ????
Code:
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim id1 As String
id1 = "InstallFiles\arc.exe"
Dim Method1 As String
Method1 = String.Format("a -t7z -m9=LZMA2 -aoa {0} {1}", BinFile1, sourceDir1)
Console.WriteLine(id1)
Dim myProcess As New Process()
AddHandler myProcess.OutputDataReceived, AddressOf myOutputHandler
Dim myProcessStartInfo As New ProcessStartInfo(id1, Method1)
myProcessStartInfo.UseShellExecute = False
myProcessStartInfo.RedirectStandardOutput = True
myProcess.StartInfo = myProcessStartInfo
myProcess.StartInfo.CreateNoWindow = False
myProcess.Start()
myProcess.BeginOutputReadLine()
End Sub
Private Shared Sub myOutputHandler(sendingProcess As Object, outLine As DataReceivedEventArgs)
Dim RichTextBox1 As String = ""
If Not String.IsNullOrEmpty(outLine.Data) Then
RichTextBox1 = RichTextBox1 + outLine.Data
End If
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|