Issue in Command line argument/String to unzip .7z files when filename contains space - vb.net

I checked .7z website FAQ and other related website for my issue. But didn't find best solution for this issue.
When .7z filename has no space then my cmd is running perfectecly for Unzip. But when zip foldername contain space then its not working.
Dim args As String = "e " + """" + zipFileFolder + """" + " -o" + ToFolder + "" + " -p""Password123""" + " -aoa"
example: Zip file name:
3344-2633-9058-4583_37DB40L1KLJU_15_07_2017__18_40_39_FSserviceLog.7z
then it is running perfectly but for this file name:
6530-0567-9050-2878
AVsetting_WD-WXS1A176FF0E_15_05_2017__17_57_37-F6serviceLog.7z
where space is there between 2878 and AVsetting, then my cmd is not working. Please guild me for this.
Please check following code:
Function extract7z(zipFileFolder As String, ToFolder As String)
Try
Dim args As String = "e " & """" & zipFileFolder & """" & " -o" & ToFolder & "" & " -p""cyberspa123""" & " -aoa"
Dim p As New Process
Dim pInfo As New ProcessStartInfo
pInfo.FileName = exePath
pInfo.Arguments = args
pInfo.WindowStyle = ProcessWindowStyle.Hidden
p.StartInfo = pInfo
p.Start()
p.WaitForExit()
' System.Diagnostics.Process.Start(exePath, args)
'Threading.Thread.Sleep(1000)
' System.IO.File.Delete(zipFileFolder)
For Each foundFile As String In My.Computer.FileSystem.GetFiles(ToFolder)
Dim check As String = System.IO.Path.GetExtension(foundFile)
If (check = ".7z") Then
Dim zipFolderpath1 As String = System.IO.Path.GetFullPath(ToFolder & "/" & System.IO.Path.GetFileNameWithoutExtension(foundFile))
extract7z(foundFile, zipFolderpath1)
End If
Next
Catch ex As Exception
Console.WriteLine(ex.Message.ToString)
MessageBox.Show(ex.Message.ToString)
End Try
End Function

Related

Compare two For Each lists in vb.net

I have a small problem.
I have two for each routines. One gives me all foldernames in the current folder. The other gives me all window names opened. Both are saving the results in a String. One with newlines, the other with ~, so I can loop through both and get all the items one by one.
This is the part:
Dim Folders As String
For Each Dir As String In System.IO.Directory.GetDirectories(My.Computer.FileSystem.CurrentDirectory & "\Data\")
Dim dirInfo As New System.IO.DirectoryInfo(Dir)
Folders = Folders & dirInfo.Name & "~"
Next
Dim FolderList() As String = Folders.Split("~")
Dim p As Process
Dim Windows As String
For Each p In Process.GetProcesses
Windows = Windows & vbNewLine & p.MainWindowTitle.ToString
Next
Windows = LineTrim(Windows)
This works. But now, I want to compare them.
I only want to get the Folders, where a window exists, which contains the foldername.
For example, I have 3 folders: Test1,Test2,Test3.
I have one Window opened: "Test1 - Window"
Now I only want to get "Test1" as Result once.
I got it working so far, but I get "Test1" 3 times, because there are 3 folders. Because I am creating new Windows by this info, my function spams new windows..
This is the whole function:
Dim Folders As String
For Each Dir As String In System.IO.Directory.GetDirectories(My.Computer.FileSystem.CurrentDirectory & "\Data\")
Dim dirInfo As New System.IO.DirectoryInfo(Dir)
Folders = Folders & dirInfo.Name & "~"
Next
Dim str As String() = Folders.Split("~")
For Each Folder As String In str
If (My.Computer.FileSystem.FileExists(My.Computer.FileSystem.CurrentDirectory & "\Data\" & Folder & "\" & "Status.txt")) Then
Dim StartTime As String = Inireader.WertLesen("Settings", "StartTime", My.Computer.FileSystem.CurrentDirectory & "\Data\" & Folder & "\Time.ini")
Dim StopTime As String = Inireader.WertLesen("Settings", "StopTime", My.Computer.FileSystem.CurrentDirectory & "\Data\" & Folder & "\Time.ini")
If (IsInTime(StartTime, StopTime) = True) Then
Dim p As Process
Dim Windows As String
For Each p In Process.GetProcesses
Windows = Windows & vbNewLine & p.MainWindowTitle.ToString
Next
Windows = LineTrim(Windows)
Dim Ar() As String = Split(Windows, Environment.NewLine)
For Each Window As String In Ar
If sX.ToString.Contains(Window & " - python " & My.Computer.FileSystem.CurrentDirectory & "\Data\" & Window& "\" & Window & ".py") Then ''''The Spam cause line
Else
Dim Path = My.Computer.FileSystem.CurrentDirectory & "\Data\" & Folder & "\" & Folder & ".py"
Dim startInfo As New ProcessStartInfo
startInfo.FileName = "cmd.exe"
startInfo.Arguments = "/k " & "title " & Folder & " & python " & Path
startInfo.WorkingDirectory = My.Computer.FileSystem.CurrentDirectory & "\Data\" & Folder & "\"
Process.Start(startInfo)
End If
Next
End If
End If
Next
I canĀ“t shorten it very much..
Could you help me out?
Thank you :)
Best regards!

How to add new display in textbox without replacing the first input

Hi I am creating a chat like application. Can you kindly help me?
When I am entering a new message the initial displayed message is getting replaced :(
Please see my codes below:
Private Sub saveMessage()
FileName = Format(Now, "MMddyyyyhhmmss")
Dim RecipientFile As String
If CurrentRecipient = "Edward" Then
RecipientFile = RecipientFolder & FileName & ".txt"
ElseIf CurrentRecipient = "Criziel" Then
RecipientFile = RecipientFolder & FileName & ".txt"
ElseIf CurrentRecipient = "Jerome" Then
RecipientFile = RecipientFile & FileName & ".txt"
Else
Exit Sub
End If
Dim Writer As IO.StreamWriter
Writer = New IO.StreamWriter(RecipientFile)
Writer.Write(MainRichTextBox.Text)
Writer.Close()
ShowtextRichTextBox.Text = (User & " : ") & MainRichTextBox.Text
MainRichTextBox.Clear()
End Sub
Thank you in advance ! :*
Your below code is just assigning (replacing) the latest value to the Rich TextBox,
ShowtextRichTextBox.Text = (User & " : ") & MainRichTextBox.Text
Instead, you should append the text as below,
ShowtextRichTextBox.Text &= (User & " : ") & MainRichTextBox.Text
Also, you can try the inbuild method of RichTextBox to append the text like, ShowtextRichTextBox.AppendText((User & " : ") & MainRichTextBox.Text)
Note: When appending, you should also add newline before the new text like, ShowtextRichTextBox.Text &= Environment.NewLine & (User & " : ") & MainRichTextBox.Text.
Modified code,
Private Sub saveMessage()
FileName = Format(Now, "MMddyyyyhhmmss")
Dim RecipientFile As String
If CurrentRecipient = "Edward" Then
RecipientFile = RecipientFolder & FileName & ".txt"
ElseIf CurrentRecipient = "Criziel" Then
RecipientFile = RecipientFolder & FileName & ".txt"
ElseIf CurrentRecipient = "Jerome" Then
RecipientFile = RecipientFile & FileName & ".txt"
Else
Exit Sub
End If
Dim Writer As IO.StreamWriter
Writer = New IO.StreamWriter(RecipientFile)
Writer.Write(MainRichTextBox.Text)
Writer.Close()
ShowtextRichTextBox.Text &= Environment.NewLine & (User & " : ") & MainRichTextBox.Text
MainRichTextBox.Clear()
End Sub

Do not show the filename when outputting the string

I'm searching for a filename and outputting it to a textbox on my form. The search is working, but I do not want to output the filename i'm searching, only the filenames of the additional filenames I've found. Any ideas? Here's my code:
Dim pathway As String = "C:\myFolder\"
Dim dirs As String() = Directory.GetFiles(pathway, "myFile" & "*.xlsm")
If dirs.Length >= 1 Then
myTextBox.Text = "Additional Reports: " & vbCrLf & String.Join(", ", dirs.Select(Function(x) Path.GetFileNameWithoutExtension(x)))
End if
You can add an "except" filter to your enumeration:
Dim pathway As String = "C:\myFolder"
Dim fileName As String = "myFile"
Dim dirs As String() = Directory.GetFiles(pathway, fileName & "*.xlsm")
If dirs.Length >= 1 Then
TextBox2.Text = "Additional Reports: " & Environment.NewLine &
String.Join(", ", dirs.Select(Function(x) Path.GetFileNameWithoutExtension(x)) _
.Except(New String() {fileName}))
End If

VB.NET StreamReader can't follow Process

I tried to get output in console program, but i got error
maybe I think that the error is about 'deadlock'
I pass night without sleep doing search solution that this error, I can't find
anyone can help me?
Someone tell me about the solution to fix it, it seems to make inherit system.
and he refer : http://programming.nullanswer.com/question/27270022
but this is java not vb.net.
Error Message:
'CTextConsoleWin32::GetLien: !GetNumberOfConsoleInputEvents'
Dim cmdCommand As String
getgame()
Serverlog.Clear()
Serverlog.Text += "ServerName : " & SelectedServer.Item(8) & " / " & "Server Download Path : " & SelectedServer.Item(9) & vbCrLf
Dim mapname As String = Split(SelectedServer.Item(2), ".bsp")(0)
cmdCommand = "-console -game " & SelectedServerGame & " -tickrate " & SelectedServer.Item(5) & " -port " & SelectedServer.Item(11) & " -maxplayers_override " & SelectedServer.Item(4) & " +map " & mapname
Serverlog.Text += (cmdCommand) & vbCrLf
Dim start_info As New ProcessStartInfo()
start_info.FileName = SelectedServer.Item(0)
start_info.UseShellExecute = False
'start_info.CreateNoWindow = True
start_info.RedirectStandardError = True
start_info.RedirectStandardOutput = True
start_info.RedirectStandardInput = True
'start_info.WindowStyle = ProcessWindowStyle.Hidden
start_info.Arguments = cmdCommand
Dim proc As New Global.System.Diagnostics.Process
proc.StartInfo = start_info
proc.Start()
Dim std_out As StreamReader = proc.StandardOutput
Do
proc.WaitForInputIdle()
Dim line As String = Await std_out.ReadLineAsync()
'Serverlog.Text += std_out.ReadLine & vbCrLf
Serverlog.Invoke(Sub() Serverlog.Text += line & vbCrLf)
Loop While proc.HasExited = False

How find excel.exe path and notpad.exe path

In my application after export excel or csv file then show the file in excel or notepad.
In this case am use
Excel:
Dim xExcelFilePath As String = System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\Microsoft Office"
xDir = New DirectoryInfo(xExcelFilePath)
For Each xDirectory As DirectoryInfo In xDir.GetDirectories ' it use for find any version of excel is installed or not
If xDirectory.Name.Count < 6 Then Continue For
If xDirectory.Name.Trim.Substring(0, 6).ToUpper = "OFFICE" Then
If System.IO.File.Exists(xExcelFilePath & "\" & xDirectory.Name & "\EXCEL.EXE") Then
xExcelFilePath = xExcelFilePath & "\" & xDirectory.Name & "\EXCEL.EXE"
Exit For
End If
End If
Next
If System.IO.File.Exists(xExcelFilePath) Then
Dim p As New Process() ' xExcelFilePath means start and stop the local system process
p.StartInfo.UseShellExecute = True
p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
p.StartInfo.FileName = xExcelFilePath ' Assaign the file name
p.StartInfo.Arguments = """" + xDestinationPath + """"
Grid1.SaveExcel(xDestinationPath, FarPoint.Win.Spread.Model.IncludeHeaders.ColumnHeadersCustomOnly) ' Export the Excel File
p.Start()
Else
Msg.Err("Could not find Excel installed on this system; file saved to:" + xExcelFilePath + ".")
End If
Notepad:
Dim p As New Process() ' xExcelFilePath means start and stop the local system process
p.StartInfo.UseShellExecute = True
p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
p.StartInfo.FileName = "C:\windows\notepad.exe"
p.StartInfo.Arguments = """" + Application.StartupPath & Grid1.ActiveSheet.SheetName & ".csv" + """"
xCSVSheet.SaveTextFile(Application.StartupPath & Grid1.ActiveSheet.SheetName & ".csv", TextFileFlags.None, Model.IncludeHeaders.BothCustomOnly, "", ",", "")
p.Start()
In above code in some system excel file path not in this order so its throw exception and Notepad exe is staticly added here. How can i get the exe file path in sysem?
Don't worry about the exact path, let Windows handle that. If you want to open a file with Notepad, simply use the following code:
Process.Start("notepad.exe", Application.StartupPath & Grid1.ActiveSheet.SheetName & ".csv")
To start the program maximized, you would have to change it to something like this:
Dim startInfo As New ProcessStartInfo("notepad.exe")
startInfo.WindowStyle = ProcessWindowStyle.Maximized
startInfo.Arguments = """" & Application.StartupPath & Grid1.ActiveSheet.SheetName & ".csv"""
Process.Start(startInfo)
Try this:
Dim excelpath = Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe", "Path", "Key does not exist")
excelpath= excelpath & "EXCEL.EXE"
Shell(Chr(34) & excelpath & Chr(34) & " " & Chr(34) & FLE & Chr(34), vbNormalFocus)
where in my case FLE is the XML file