4

我遇到了 Unicode 命名文件夹的问题。当我将文件夹拖到脚本时,它没有正确显示文件夹的路径。

简单的 VBScript(这只是其中的一部分):

Dim Wshso : Set Wshso = WScript.CreateObject("WScript.Shell")
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")

If WScript.Arguments.Count = 1 Then
    If FSO.FileExists(Wscript.Arguments.Item(0)) = true and FSO.FolderExists(Wscript.Arguments.Item(0)) = false Then
        Alert "You dragged a file, not a folder! My god." & vbcrlf & "Script will terminate immediately", 0, "Alert: User is stupid", 48
        WScript.Quit
    Else
        targetDir = WScript.Arguments.Item(0)
        Wshso.Popup targetDir
    End If
Else
    targetDir = Wshso.SpecialFolders("Desktop")
    Alert "Note: No folder to traverse detected, default set to:" & vbcrlf & Wshso.SpecialFolders("Desktop"), 0, "Alert", 48
End If

如果是没有 Unicode 字符的普通路径,那就没问题了。但在这种情况下:目录:4minute (포미닛) - Hit Your Heart

然后它会显示类似4minute (?) - Hit Your Heart

如果我做一个 FolderExists 它找不到拖动的文件夹。

是否有任何解决方法来支持 Unicode 命名文件夹?

谢谢!

如果这不够清楚,我会编辑

4

4 回答 4

4
于 2010-12-06T13:34:49.033 回答
2

For anyone landing here from Google...

Bobince's tip lead me to work around this problem by wrapping my vbscript file (myscript.vbs) in a dos batch file (mybatch.bat).

The tip was:

"Seem to be a problem peculiar to the Windows Script Host's DropHandler shell extension whereas.... the one used for .exe, .bat and similar... doesn't suffer from this issue."

mybatch.bat contains:

:Loop
IF "%1"=="" GOTO Continue
     set allfiles=%allfiles% "%1"
SHIFT
GOTO Loop
:Continue
"myscript.vbs" %allfiles%

You may also find this code from my myscript.vbs to be helpful

For Each strFullFileName In Wscript.Arguments
  ' do stuff
Next
于 2012-11-27T15:46:16.450 回答
0

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
于 2018-09-08T20:14:44.203 回答
0

Modify WSH DropHandler ({60254CA5-953B-11CF-8C96-00AA00B8708C}) to {86C86720-42A0-1069-A2E8-08002B30309D} and add this function to convert short path to long:

Function Short2Long(shortFullPath)
    dim fs
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFile(shortFullPath)
    Set app = CreateObject("Shell.Application")
    Short2Long = app.NameSpace(f.ParentFolder.Path).ParseName(f.Name).Path
end function
于 2020-01-15T17:05:30.290 回答