try to save a UTF file name

Big Monty
Big Monty used Ask the Experts™
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.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2013

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
Dave BaldwinFixer of Problems
Most Valuable Expert 2014
This page says...
On newer file systems, such as NTFS, exFAT, UDFS, and FAT32, Windows stores the long file names on disk in Unicode, which means that the original long file name is always preserved. This is true even if a long file name contains extended characters, regardless of the code page that is active during a disk read or write operation.
This page however says Windows uses UTF-16 encoding.
Big MontyWeb Ninja at large


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?
Top Expert 2013
Rename the file in the web app straight after upload and before passing it to the dll. Replace the utf characters with some Latin equivalents
Big MontyWeb Ninja at large


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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial