Archive

Posts Tagged ‘Unicode’

Gotcha: VBScript DropHandler doesn’t support Unicode filenames

It seems VBScript (.vbs) script file’s DropHandler on Windows is broken regarding Unicode filenames, as described at https://stackoverflow.com/a/4366906/903783

A workaround suggested by user DG there (https://stackoverflow.com/a/13587850/903783) was to use a batch file to accept the dropped file, then pass the filename(s) to the VBScript script file (.vbs) as command-line parameters. If you just care about a single instead of multiple dropped files, there’s a simpler version of a batch file one can use, as I suggested at https://stackoverflow.com/a/52239049/903783. Copying below:


Based on DG’s answer, if you just want to accept one file as drop target then you can write a batch file (if you have it named as "x.bat" place VBscript with filename "x.bat.vbs" at same folder) that just contains:

@"%0.vbs" %1

the @ means to not output the row on the display (I found it to show garbage text even if you use chcp 1250 as first command)

don’t use double-quotes around %1, it won’t work if your VBScript uses logic like the following (code I was using below was from http://jeffkinzer.blogspot.com/2012/06/vbscript-to-convert-excel-to-csv.html). Tested it and it works fine with spaces in the file and folder names:

  Dim strExcelFileName
  strExcelFileName = WScript.Arguments.Item(0) 'file name to parse

  ' get path where script is running
  strScript = WScript.ScriptFullName
  Dim fso
  Set fso = CreateObject ("Scripting.FileSystemObject") 
  strScriptPath = fso.GetAbsolutePathName(strScript & "\..")
  Set fso = Nothing

  ' If the Input file is NOT qualified with a path, default the current path
  LPosition = InStrRev(strExcelFileName, "\")
  if LPosition = 0 Then 'no folder path
    strExcelFileName = strScriptPath & "\" & strExcelFileName
    strScriptPath = strScriptPath & "\"
  else 'there is a folder path, use it for the output folder path also
    strScriptPath = Mid(strExcelFileName, 1, LPosition)
  End If
  ' msgbox LPosition & " - " & strExcelFileName & " - " & strScriptPath
Advertisements

HowTo: Use DotNetZip (Ionic.Zip) library in Silverlight

If you want to use the latest DotNetZip library (version 1.9.1.8) with Silverlight, you should get a patched version from http://dotnetzip.codeplex.com/workitem/14049, instead of the official download for Silverlight.

It seems the Silverlight build in 1.9.1.8 official download doesn’t work correctly, since it tries to get IBM437 Encoding (as the original ZIP spec required) from Silverlight, but that encoding is not available via Encoding.GetEncoding method in Silverlight (neither encoder and decoder fallbacks for GetEncoding are available as in .NET 4.5).

So the patched version uses Unicode encoding instead (only UTF-8 and Unicode [UTF-16] Encodings are available in Silverlight), although it could have also used a text encoding class generator for the missing encoding and change the source code similar to how Mike Taulty had done with an older version of DotNetZip.

I do prefer the Unicode approach, since using the IBM437 codepage would have issues with Unicode filenames. ZIPs with such filenames are supported fine by most modern ZIP viewers, including Windows Explorer’s Compressed Folders views in recent versions of Windows.

%d bloggers like this: