Avatar of Big Monty
Big Monty
Flag 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.
Visual Basic ClassicMicrosoft Development

Avatar of undefined
Last Comment
Big Monty

8/22/2022 - Mon
chaau

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
    
    'FILENAME MUST EXIST FOR API FUNCTION TO WORK
    'SO CREATE THE FILE IF IT DOESN'T EXISTS
    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
SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Big Monty

ASKER
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?
ASKER CERTIFIED SOLUTION
chaau

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Big Monty

ASKER
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.
Your help has saved me hundreds of hours of internet surfing.
fblack61