[ mpaja @ 29.01.2016. 17:22 ] @
Pozdrav svima,

Pojavio mi se neobičan problem za koji nisam dovoljno stručan, pa ako neko može da pomogne:

imam file-ove čija su imena napisana ćirilicom, potrebno je da ih preimenujem tako da naziv ostane isti ali na latinici. Na forumima nisam uspeo da nadjem adekvatno rešenje za access VBA jer ta operacija treba da se uradi u access 2003 VBA.


Ako ima neko raspoložen, dugujem zahvalnost

[ Getsbi @ 30.01.2016. 07:31 ] @
Nije baš najjasnije: 1. Jesu li to .mdb fajlovi sa nazivima nekih stavki u tabelama koje su na ćiriličnom pismu pa ih treba konvertovati u latinicu i tako dobiti tabele sa latiničnim sadržajem. 2. Ili su to neki spoljni fajlovi van .mdb kontejnera kao na primer: Dokument1.doc, Cenovnik.xls, Prezentacija proizvoda.ppt, sa ćiriličnim nazivima, koji se nalaze u nekom folderu i treba ih preimneovati sa istim nazivima u latinično pismo.
Ako je u pitanju opcija pod 1., onda ima nekoliko dobrih tema. U pretragu ukucati ćirilica u latinicu i pritisnuti dugme Ovog foruma (ne Google-ES).
Ako je opcija 2. onda dobra rešenja postoje u forumu PHP , pa bi to valjalo istražiti.


PS. Evo ti za prvu opciju jedan primer (doduše kontra) ali se može prepraviti.
[ mpaja @ 30.01.2016. 07:41 ] @
To su spoljni file-ovi (xxx.pdf, xxx.doc....) i nisu u mdb (eh da jesu...). Ti file-ovi imaju naziv ispisan ćirilicom i to je problem (primer: dokument.pdf). Poslao sam i primer uz poruku. Ako ima neko rešenje koje se može primeniti kroz access VBA makar i sa shell f-jom (Call Shell( prog file, fileren)) bilo bi ekstra.

Hvala!
[ Getsbi @ 30.01.2016. 11:31 ] @
Izgleda da sam ti našao rešenje. Bar tako kaže postavljač teme. Pogledaj ovaj link na forumu Windows aplikacije.
http://www.elitesecurity.org/t306433-0

Pročitaj temu do kraja. Član DakSrbija se hvali da je uspeo.


PS. Evo ja isprobao. Stvarno radi.

[Ovu poruku je menjao Getsbi dana 30.01.2016. u 14:56 GMT+1]
[ mpaja @ 30.01.2016. 13:57 ] @
Nazalost to nije to što mi treba. Ovoj čovek našao renamer program-aplikaciju koja se instalira a ne mogućnost da se to uradi preko koda VBA na neki even na formi, ili slično. Evo koda u koji nekako treba ubaciti da se ono što se pročita kao ime file-a, preimenuje u latinični naziv:

Dim testA() As String
Dim gfile, latfile As String
Dim LastNonEmpty, i As Integer
Dim vrtSelectedItem As Variant
Dim retlist As Variant
Dim ibroj As Integer

Dim fd As Office.FileDialog
Dim rstTemp As Recordset


Set rstTemp = Me.RecordsetClone

If rstTemp.RecordCount = 0 Then
MsgBox "Nema predmeta za obradu", vbInformation
Exit Sub

End If


Set fd = Application.FileDialog(msoFileDialogFilePicker)

retlist = ""


With fd
.Filters.Clear
.AllowMultiSelect = True
.Title = "Izaberite file-ove"
.Filters.Add "All files", "*.*"

'.Filters.Add "Access Database", "*.mdb", 1
If .Show = -1 Then

For Each vrtSelectedItem In .SelectedItems

latfile = Cir2Lat(vrtSelectedItem) <- f-ja koja ime prebaci u latinicu, to radi OK

Name vrtSelectedItem As latfile <- ovo ne radi jer vrtSelectedItem je na ćirilici !!! (pokazuje ???????...) i tu dojavljuje grešku


retlist = vrtSelectedItem

LastNonEmpty = 0
testA = Split(retlist & "\", "\")

For i = 0 To UBound(testA) - 1
If testA(i) <> "" Then
testA(LastNonEmpty) = Cir2Lat(testA(i))
LastNonEmpty = LastNonEmpty + 1

End If
Next

ReDim Preserve testA(LastNonEmpty - 1)
gfile = testA(UBound(testA))

If Len(Dir(dbput & "Edokumenti\" & Me.Field48, vbDirectory)) = 0 Then
MkDir dbput & "Edokumenti\" & Me.Field48
End If

gfile = Replace(gfile, " ", "_")
FileCopy retlist, dbput & "Edokumenti\" & Me.Field48 & "\" & gfile <- ovde pravi grešku jer je retlist ime file-a čirilicom (opet ?????...) i neće da kopira!!!

Next vrtSelectedItem

Else

End If
End With
Set fd = Nothing
MsgBox "Kopiranje završeno...", vbInformation, "Kopiranje..."

Cilj je da se u okviru ovog koda nekako prebaci naziv file-a sa ćirilice na latinicu i odradi posao dalje a ne renamer koji treba ručno pokrenuti, pa selektovati file-ove....
Može i neka bat proceudra koja bi se pokrenula kroz shell ili ...


Hvala Getsbi

[ mpaja @ 31.01.2016. 10:18 ] @
Probao sam i sa BAT procedurom:

@echo off
RENAME %~1 %~2

gde je 1 naziv file-a na cirilici a 2 na latinici. Iz komand prompta ovo radi OK, medjutim VBA ne poznaje naziv na cirilici i ne može se proslediti parametar iz VBA BAT proceduri.

Idemo dalje....
[ Getsbi @ 31.01.2016. 11:28 ] @
Pročitj ovo: http://www.elitesecurity.org/t453669-0#3145646

i sve što izguglaš o VBA i ćirilici.
[ mpaja @ 31.01.2016. 11:56 ] @
Ma ovo je sve OK.

Nije mi problem da baratam sa sadržajem file-a ili podacima u bazi, za to već postoje f-je. Problem je ime file-a koje je ispisano ćirilicom, IME FILE-a a ne sadržaj. Kada pročitam ime file-a preko VBA imam ?????? ili sl. Ime je string unicode, njega mogu da prebacim u latinicu i to nije problem. Problem je što preko VBA ne mogu izvorni naziv file-a da promenim u latinični pri tome me ne interesuje sadržaj samog file-a. Jednostavno VBA u tom slučaju ne vidi izvorno ćirilično ime i javlja grešku.

Probajte kod koji sam postavio i označio gde su problemi ili

dajte nekom file-u ime ispisano ćirilicom i probajte da ga preimenujete ili prekopirate u drugi file ili isti file samo sa latiničnim imenom kroz VBA.

Idemo dalje...
[ mpaja @ 31.01.2016. 16:26 ] @
Nešto sam našao guglajući, ali koliko vidim svi koji rade sa VB imaju taj problem.

Na http://forums.codeguru.com/sho...p?481974-Rename-a-unicode-file

sam našao ovo:

VB6 cannot handle unicode correctly, e.g. if you have a filename with japanese characters, they will be displayed in a VB6 program as ?????

You have to use a winapi function, I think it is CopyFileApiW to copy and to rename files:
Declare Function CopyFileApiW Lib "kernel32" Alias "CopyFileW" ( _
ByVal lpExistingFileName As Long, _
ByVal lpNewFileName As Long, _
ByVal bFailIfExists As Long) _
As Long

retval = CopyFileApiW(StrPtr(source), StrPtr(StrConv(Dest), 0)

Da li neko može da proba ....
[ mpaja @ 31.01.2016. 16:31 ] @
Ima i ovde nekih stvari

http://forums.codeguru.com/sho...pening-unicode-filenames-in-XP

nemam toliko znanja, da sve razumem, može li pomoć?

Hvala!
[ mpaja @ 31.01.2016. 16:37 ] @
Da li je ovo rešenje?

Option Explicit

Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameW" (pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameW" (ByRef pOpenfilename As OPENFILENAME) As Long

Private Type OPENFILENAME
lStructSize As Long
hWndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Dim sString As String

Private opFile As OPENFILENAME
Private fso As FileSystemObject

Private Function ShowOpenUnicode() As String
With opFile
.flags = &H2 Or &H4
.hInstance = App.hInstance
.hWndOwner = Me.hWnd
.lpstrFilter = StrConv(("Text Files" & Chr(0) & "*.txt" & Chr(0) & Chr(0)), vbUnicode)
.lpstrTitle = StrConv("Open File", vbUnicode)
.lpstrFile = StrConv(String(256, Chr(0)), vbUnicode)
.nMaxFile = 512
.lStructSize = Len(opFile)
End With
Call GetOpenFileName(opFile)

ShowOpenUnicode = opFile.lpstrFile
End Function

Private Function ShowSaveUnicode() As String
With opFile
.flags = &H2 Or &H4
.hInstance = App.hInstance
.hWndOwner = Me.hWnd
.lpstrFilter = StrConv(("Text Files" & Chr(0) & "*.txt" & Chr(0) & Chr(0)), vbUnicode)
.lpstrTitle = StrConv("Save File", vbUnicode)
.nMaxFile = 512
.lpstrFile = sString & String(512 - Len(sString), Chr(0))
.lStructSize = Len(opFile)
End With
Call GetSaveFileName(opFile)

ShowSaveUnicode = opFile.lpstrFile
End Function

Private Function ConvertFileName(sToConvert) As String
Dim bFileName() As Byte
Dim lRet As Long
Dim sBuf As String
'Get rid of the trailing Null characters
sToConvert = Left$(sToConvert, InStr(sToConvert, (Chr(0) & Chr(0))) - 1)

If Len(sToConvert) Mod 2 <> 0 Then
sToConvert = sToConvert & Chr(0) 'If the file has an ANSI extension or just an ANSI last character of
'a file with no extension, add one on the end
'If we don't add it, the string will end one character too short
End If

bFileName = StrConv(sToConvert, vbFromUnicode) 'Put the string into a byte array

sBuf = ""
For lRet = 0 To Len(sToConvert) - 1 Step 2
'At this point, the unicode characters will show up in sBuf as ?, but, when we actually go
'to use this in the FSO function, it will find the right file
sBuf = sBuf & StrConv(Chr(bFileName(lRet)) & Chr(bFileName(lRet + 1)), vbFromUnicode)
Next

'And return the string for use
ConvertFileName = sBuf
End Function


Private Sub UnicodeSaveMethod()
Dim sFileName As String

'Show the save dialog and get the file path as Unicode in a VB String
sFileName = ShowSaveUnicode

If Left$(sFileName, 1) = Chr(0) Then Exit Sub 'Exit on Cancel
'Convert the file name to be used
sFileName = ConvertFileName(sFileName)

'Here is where you'd create the file, input the text, and save it
'For this example, I just try to create the file
Call fso.CreateTextFile(sFileName, False)
End Sub

Private Sub UnicodeOpenMethod()
Dim sFileName As String

'Show the open dialog and get the file path as Unicode in a VB String
sFileName = ShowOpenUnicode

If Left$(sFileName, 1) = Chr(0) Then Exit Sub 'Exit on Cancel
'Convert the file name to be used
sFileName = ConvertFileName(sFileName)

'This line will print everything in the file to show you it works
'Otherwise, you'd have normal open/read/etc code here
Debug.Print fso.OpenTextFile(sFileName, ForReading, False).ReadAll
End Sub

Private Sub Form_Load()
Set fso = New FileSystemObject
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set fso = Nothing
End Sub

Private Sub Command1_Click()
UnicodeOpenMethod
End Sub

Private Sub Command2_Click()
UnicodeSaveMethod
End Sub
[ mpaja @ 02.02.2016. 16:12 ] @
Problem nije rešen ali u traganju se našlo nešto drugo.

U prilogu je VBA kod koji otvara file-ove i pokreće aplikacije (pdf...) a možda se ,ože iskoristiti i za nešto još...

Upotrebio sam deo koda i rešio problem

Pozdrav i havala na pomoći svima!