|
-
Jan 27th, 2015, 01:32 PM
#1
Thread Starter
Hyperactive Member
[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:
Private Const INTERNET_OPEN_TYPE_DIRECT = 1
Private Const INTERNET_OPEN_TYPE_PROXY = 3
Private Const IF_FROM_CACHE = &H1000000
Private Const IF_MAKE_PERSISTENT = &H2000000
Private Const IF_NO_CACHE_WRITE = &H4000000
Private Const BUFFER_LEN = 256
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
Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
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
Public Function Inet(sURL As String, scUserAgent As String, Optional sProxy As String, Optional sHeaders As String) As String
Dim hOpen As Long, hFile As Long, sBuffer As String * BUFFER_LEN, iResult As Integer, sData As String, lReturn As Long
On Error GoTo Error
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)
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&)
If hFile Then
iResult = InternetReadFile(hFile, sBuffer, BUFFER_LEN, lReturn)
sData = sBuffer
Do While lReturn <> 0
iResult = InternetReadFile(hFile, sBuffer, BUFFER_LEN, lReturn)
sData = sData + Mid(sBuffer, 1, lReturn)
Loop
End If
InternetCloseHandle hFile
InternetCloseHandle hOpen
Inet = sData
Error: Exit Function
End Function
Sub Main()
Dim strUserAgent As String, strName As String
strUserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:35.0) Gecko/20100101 Firefox/35.0"
strName = Split(Split(Inet("https://www.youtube.com/watch?v=gi7gs4EGnCI", strUserAgent), "<title>")(1), " - YouTube")(0)
Open strName & ".txt" For Output As #1
Print #1, strName
Close #1
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|