Results 1 to 10 of 10

Thread: Batch command in specific folder ??

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2014
    Posts
    81

    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.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Oct 2014
    Posts
    81

    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?

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    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.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2014
    Posts
    81

    Re: Batch command in specific folder ??

    Quote Originally Posted by jmcilhinney View Post
    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....

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Batch command in specific folder ??

    Quote Originally Posted by mingolito View Post
    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.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2014
    Posts
    81

    Re: Batch command in specific folder ??

    Quote Originally Posted by jmcilhinney View Post
    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"

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    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.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Oct 2014
    Posts
    81

    Re: Batch command in specific folder ??

    Quote Originally Posted by jmcilhinney View Post
    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.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2014
    Posts
    81

    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.

    Name:  1.jpg
Views: 127
Size:  12.8 KB
    Name:  3.png
Views: 134
Size:  33.1 KB

    I would like to show the flow of control during compression as it appears in the DOS window ... !!! Someone can help me on this ????

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Oct 2014
    Posts
    81

    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
  •  



Click Here to Expand Forum to Full Width