Results 1 to 11 of 11

Thread: [RESOLVED] Unicode filename

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2011
    Posts
    461

    Resolved [RESOLVED] Unicode filename

    I have searched the Internet for solution but I haven't found any.

    Like I said in title, I want to give unicode filename to some file, nevertheless if I do that directly (for example with command "Open [file] For Output ..."), or renaming it later (i.e. command "Name [file] As [newfile]"), because it does not work in both cases.

    Here is example code where I want to extract YouTube title (which in this case is in Russian) and use that as filename (put this code in module and run):
    VB Code:
    1. Private Const INTERNET_OPEN_TYPE_DIRECT = 1
    2. Private Const INTERNET_OPEN_TYPE_PROXY = 3
    3. Private Const IF_FROM_CACHE = &H1000000
    4. Private Const IF_MAKE_PERSISTENT = &H2000000
    5. Private Const IF_NO_CACHE_WRITE = &H4000000
    6. Private Const BUFFER_LEN = 256
    7. Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
    8. Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
    9. Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
    10. Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
    11.  
    12. Public Function Inet(sURL As String, scUserAgent As String, Optional sProxy As String, Optional sHeaders As String) As String
    13. Dim hOpen As Long, hFile As Long, sBuffer As String * BUFFER_LEN, iResult As Integer, sData As String, lReturn As Long
    14. On Error GoTo Error
    15. If Not InStr(1, sProxy, ":") > 0 And Not InStr(1, sProxy, ".") > 0 Then hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0) Else: hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PROXY, sProxy, vbNullString, 0)
    16. If sHeaders = "" Then hFile = InternetOpenUrl(hOpen, sURL, vbNullString, ByVal 0&, IF_NO_CACHE_WRITE, ByVal 0&) Else: hFile = InternetOpenUrl(hOpen, sURL, sHeaders, CLng(Len(sHeaders)), IF_NO_CACHE_WRITE, ByVal 0&)
    17. If hFile Then
    18. iResult = InternetReadFile(hFile, sBuffer, BUFFER_LEN, lReturn)
    19. sData = sBuffer
    20. Do While lReturn <> 0
    21. iResult = InternetReadFile(hFile, sBuffer, BUFFER_LEN, lReturn)
    22. sData = sData + Mid(sBuffer, 1, lReturn)
    23. Loop
    24. End If
    25. InternetCloseHandle hFile
    26. InternetCloseHandle hOpen
    27. Inet = sData
    28. Error: Exit Function
    29. End Function
    30.  
    31. Sub Main()
    32. Dim strUserAgent As String, strName As String
    33. strUserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:35.0) Gecko/20100101 Firefox/35.0"
    34. strName = Split(Split(Inet("https://www.youtube.com/watch?v=gi7gs4EGnCI", strUserAgent), "<title>")(1), " - YouTube")(0)
    35. Open strName & ".txt" For Output As #1
    36. Print #1, strName
    37. Close #1
    38. End Sub
    Result is:

    which is not valid.
    But, in that file is also written YouTube title, and it is in it's original state:


    Does somebody know solution for this problem? Thanks in advance!
    Last edited by MikiSoft; Jan 27th, 2015 at 05:20 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width