Page 1 of 1

handling with unicode - files/folder ?

Posted: Tue Apr 26, 2005 7:10 pm
by bingo
how can use "Deletedirectory" / "ExamineDirectory" with unicode-folders ?

"c:\λογαριασμό" :cry:

Only with SHFileOperation (#FO_DELETE) and FindfirstfileW ?

Posted: Wed Apr 27, 2005 12:18 pm
by bingo
:lol: a way ... (sample-code to kill unicode-folders/files)

Code: Select all

Procedure.l Ansi2Uni(ansi.s) 
  size.l=MultiByteToWideChar_(#CP_ACP,0,ansi,-1,0,0) 
  Dim unicode.w(size) 
  MultiByteToWideChar_(#CP_ACP, 0, ansi, Len(ansi), unicode(), size) 
  ProcedureReturn @unicode()  
EndProcedure

Procedure.s Uni2Ansi(*Unicode.l) 
size.l = WideCharToMultiByte_(#CP_ACP, 0, *Unicode, -1, #Null, #Null, #Null, #Null) 
ansi.s=Space(size) 
WideCharToMultiByte_(#CP_ACP, 0, *Unicode, -1, @ansi, size, #Null, #Null) 
ProcedureReturn ansi  
EndProcedure

Procedure killdir(dirpoint.l)
SHFO.SHFILEOPSTRUCT 
SHFO\hwnd   = 0
SHFO\wFunc  = #FO_DELETE
SHFO\pFrom  = dirpoint 
SHFO\pTo    = 0
SHFO\fFlags = #FOF_SILENT|#FOF_NOCONFIRMATION
OpenLibrary (1, "shell32.dll") 
CallFunction (1,"SHFileOperationW",SHFO)
CloseLibrary(1)
EndProcedure

fp.WIN32_FIND_DATA

subdirtokill.s = "c:\test\"
notokill.s = "test.123"

*MemoryID = AllocateMemory(500)
OpenLibrary (0, "kernel32.dll") 
ret = CallFunction (0,"FindFirstFileW",Ansi2Uni(subdirtokill + "*"),@fp)
CallFunction (0,"FindNextFileW",ret,@fp)
While CallFunction (0,"FindNextFileW",ret,@fp) > 0
;compare notokill
If notokill <> LCase(Uni2Ansi(@fp\cFileName))
  CopyMemory(Ansi2Uni(subdirtokill), *MemoryID, Len(subdirtokill)*2)
  CopyMemory(@fp\cFileName, *MemoryID + Len(subdirtokill)*2 , CallFunction (0,"lstrlenW",@fp\cFileName) * 2)
  killdir(*MemoryID)
  zeromemory_(*MemoryID,500)
EndIf
Wend
CallFunction (0,"FindClose",ret)
CloseLibrary(0)
FreeMemory(*MemoryID)
delete all files/folders in "c:\test" except "test.123" . also delete this subfolders (unicode names !) :

c:\test\ημέρας
c:\test\Почта

:D

no way with "Deletedirectory" / "ExamineDirectory" and unicode names !

(pb3.93 xp sp2)