Question Batch to remove file w unicode characters

d_a_r_k

Member
Joined
Oct 30, 2010
Messages
19
Programming Experience
Beginner
Hello, I made a batch script using VB.NET which deletes shortcut on my desktop. The problem is that shortcut title contains unicode characters so batch doesn't work. However if I remove that unicode character from the shortcut and batch script it does delete the shortcut. How can I make it delete the shortcut w/o removing that unicode character?

VB.NET:
tempstring = "@echo off"
tempstring = tempstring & vbCrLf & "del " & Chr(34) & My.Computer.FileSystem.SpecialDirectories.Desktop & "\My shortcut™ 1.lnk" & Chr(34)
tempstring = tempstring & vbCrLf & "del %0"
My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.Temp & "\temp.bat", tempstring, False, System.Text.Encoding.Default)
Shell(My.Computer.FileSystem.SpecialDirectories.Temp & "\temp.bat", AppWinStyle.Hide)
 
You call WriteAllText with Encoding.Default, obviously that encoding is not appropriate. For Unicode encoding use Encoding.UTF8/Unicode/UTF32.
 
You call WriteAllText with Encoding.Default, obviously that encoding is not appropriate. For Unicode encoding use Encoding.UTF8/Unicode/UTF32.
None of them worked. Unicode and UTF32 made my batch file unreadable causing an error when executed. However UTF8 seemed to work but again it didn't remove that shortcut.
 
You could output to a specific codepage encoding and include chcp command (change codepage) in batch file to accommodate that. For example "Encoding.Default" and batch command chcp with same codepage "Encoding.Default.CodePage".
 
Back
Top