Link to home
Create AccountLog in
Avatar of Big Monty
Big MontyFlag for United States of America

asked on

try to save a UTF file name

I have a website that allows users to upload files. Some of those files may contain special characters, such as chinese or japanese characters in the file name. While my upload piece works fine, I call a DLL that was written in VB6 that does some processing of the file (saves meta data to the database).

my problem lies in trying to read these files with special characters in them. I haven't been able to find a way to encode these characters, the only thing I can find online is to encode entire files by creating a memory stream and encoding the bytes as the go into memory, then write it to a file. What I want to do is simply encode the file name so I can access it and its path in my VB6 dll.
Avatar of chaau
Flag of Australia image

any file with the extended characters has a 8.3 mapping, i.e. your "C:\Program Files" folder is also accessible as "C:\progra~1". There are different ways of getting the 8.3 filename. One of the easiest is to use a GetShortPathName API:
Option Explicit

Private Declare Function GetShortPathName Lib "kernel32" _ 
   Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
   ByVal lpszShortPath As String, ByVal cchBuffer As Long) _
   As Long
Public Function ShortPath(ByVal strFilename As String) As String
    Dim strBuffer As String * 255
    Dim lngReturnCode As Long
    Dim iFileNumber As Integer
    iFileNumber = FreeFile
    If Dir(strFilename) = "" Then
        On Error Resume Next
        Open strFilename For Output As #iFileNumber
        Close #iFileNumber
    End If
    lngReturnCode = GetShortPathName(strFilename, strBuffer, 255)
    ShortPath = Left$(strBuffer, lngReturnCode)
End Function

Open in new window

And here is an example from MSDN
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Big Monty


i don't think I explained myself well enough...

i have the file already uploaded on to the server. This is done via my web app. after the upload, my dll is called to do some basic processing of the file, and the file name (including the path) is passed as a parameter to the function in the dll i'm calling. one of the processing steps is to move the file to it's final location. the path that's being passed into the function contains japanese characters, which is causing the move functionality to bomb because it cannot read those characters. is there a way, in VB6, to get around that?
Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
renaming the file before passing it to the DLL is the method I'm going to take. Although this was decided before your comment, I'll award the points for the different ideas.