Character Problem Despite UTF-8 Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
hasantr
Posts: 678
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Character Problem Despite UTF-8

22 Sep 2020, 12:08

I am using the RunCmd function made by SKAN.
My goal is to get the path to all exe files. (very quickly)

Code: Select all

MsgBox % RunCmd( A_Comspec . " /c dir /S /B /A:-D *.exe | findstr /V /I /C:""""\\Microsoft\\"""" /C:""""$Recycle.Bin"""" /C:""""\\Windows\\""""" , "D:\","UTF-8")


RunCMD(CmdLine, WorkingDir:="", Codepage:="CP0", Fn:="RunCMD_Output") {  ;         RunCMD v0.94        
	Local         ; RunCMD v0.94 by SKAN on D34E/D37C @ autohotkey.com/boards/viewtopic.php?t=74647                                                             
	Global A_Args ; Based on StdOutToVar.ahk by Sean @ autohotkey.com/board/topic/15455-stdouttovar
	
	Fn := IsFunc(Fn) ? Func(Fn) : 0
, DllCall("CreatePipe", "PtrP",hPipeR:=0, "PtrP",hPipeW:=0, "Ptr",0, "Int",0)
, DllCall("SetHandleInformation", "Ptr",hPipeW, "Int",1, "Int",1)
, DllCall("SetNamedPipeHandleState","Ptr",hPipeR, "UIntP",PIPE_NOWAIT:=1, "Ptr",0, "Ptr",0)
	
, P8 := (A_PtrSize=8)
, VarSetCapacity(SI, P8 ? 104 : 68, 0)                          ; STARTUPINFO structure      
, NumPut(P8 ? 104 : 68, SI)                                     ; size of STARTUPINFO
, NumPut(STARTF_USESTDHANDLES:=0x100, SI, P8 ? 60 : 44,"UInt")  ; dwFlags
, NumPut(hPipeW, SI, P8 ? 88 : 60)                              ; hStdOutput
, NumPut(hPipeW, SI, P8 ? 96 : 64)                              ; hStdError
, VarSetCapacity(PI, P8 ? 24 : 16)                              ; PROCESS_INFORMATION structure
	
	If not DllCall("CreateProcess", "Ptr",0, "Str",CmdLine, "Ptr",0, "Int",0, "Int",True
                ,"Int",0x08000000 | DllCall("GetPriorityClass", "Ptr",-1, "UInt"), "Int",0
                ,"Ptr",WorkingDir ? &WorkingDir : 0, "Ptr",&SI, "Ptr",&PI)  
		Return Format("{1:}", "", ErrorLevel := -1
                   ,DllCall("CloseHandle", "Ptr",hPipeW), DllCall("CloseHandle", "Ptr",hPipeR))
	
	DllCall("CloseHandle", "Ptr",hPipeW)
, A_Args.RunCMD := { "PID": NumGet(PI, P8? 16 : 8, "UInt") }      
, File := FileOpen(hPipeR, "h", Codepage)
	
, LineNum := 1,  sOutput := ""
	While (A_Args.RunCMD.PID + DllCall("Sleep", "Int",0))
    and DllCall("PeekNamedPipe", "Ptr",hPipeR, "Ptr",0, "Int",0, "Ptr",0, "Ptr",0, "Ptr",0)
		While A_Args.RunCMD.PID and (Line := File.ReadLine())
			sOutput .= Fn ? Fn.Call(Line, LineNum++) : Line
	
	A_Args.RunCMD.PID := 0
, hProcess := NumGet(PI, 0)
, hThread  := NumGet(PI, A_PtrSize)
	
, DllCall("GetExitCodeProcess", "Ptr",hProcess, "PtrP",ExitCode:=0)
, DllCall("CloseHandle", "Ptr",hProcess)
, DllCall("CloseHandle", "Ptr",hThread)
, DllCall("CloseHandle", "Ptr",hPipeR)
	
, ErrorLevel := ExitCode
	
	Return sOutput  
}
What should I do to ensure that all characters are read correctly.
Could not read a character in the sample image.

Image
Last edited by hasantr on 23 Sep 2020, 13:55, edited 1 time in total.
effel
Posts: 265
Joined: 16 Jan 2018, 13:34

Re: UTF-8'e Rağmen Karakter Sorunu

22 Sep 2020, 14:02

FileEncoding, UTF-8
User avatar
hasantr
Posts: 678
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: UTF-8'e Rağmen Karakter Sorunu

22 Sep 2020, 14:34

effel wrote:
22 Sep 2020, 14:02
FileEncoding, UTF-8
Unfortunately this doesn't work.
User avatar
Smile_
Posts: 306
Joined: 03 May 2020, 00:51

Re: UTF-8'e Rağmen Karakter Sorunu

22 Sep 2020, 17:11

Code: Select all

List := ""
Loop, Files, D:\*.exe, R
    List .= A_LoopFileFullPath "`n"
MsgBox %List%
garry
Posts: 2460
Joined: 22 Dec 2013, 12:50

Re: UTF-8'e Rağmen Karakter Sorunu

23 Sep 2020, 08:15

or also , show files with the extension 'exe' in D:\

Code: Select all

mf:="D:\"
setworkingdir,%MF%
runwait,%comspec% /c dir /b /s *.exe |clip,,hide
msgbox,%clipboard%
just me
Posts: 7431
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: UTF-8'e Rağmen Karakter Sorunu

23 Sep 2020, 10:51

What is shown when you use the default CP0?
User avatar
hasantr
Posts: 678
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: UTF-8'e Rağmen Karakter Sorunu

23 Sep 2020, 13:18

just me wrote:
23 Sep 2020, 10:51
What is shown when you use the default CP0?
The corrupted character is different but still distorted.

Image
User avatar
hasantr
Posts: 678
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: UTF-8'e Rağmen Karakter Sorunu

23 Sep 2020, 13:20

Smile_ wrote:
22 Sep 2020, 17:11

Code: Select all

List := ""
Loop, Files, D:\*.exe, R
    List .= A_LoopFileFullPath "`n"
MsgBox %List%
Thanks for the suggestion.
There will be more than one format. doc docx pdf odf rtf etc. Could the loop be the fastest method?
User avatar
hasantr
Posts: 678
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: UTF-8'e Rağmen Karakter Sorunu

23 Sep 2020, 13:25

garry wrote:
23 Sep 2020, 08:15
or also , show files with the extension 'exe' in D:\

Code: Select all

mf:="D:\"
setworkingdir,%MF%
runwait,%comspec% /c dir /b /s *.exe |clip,,hide
msgbox,%clipboard%
It can be an alternative. Thank you.
But I wish I could do it without using the clipboard.
gregster
Posts: 5389
Joined: 30 Sep 2013, 06:48

Re: UTF-8'e Rağmen Karakter Sorunu

23 Sep 2020, 13:29

@hasantr:would you mind to please translate the topic title to english? ;) Thank you!

I was waiting and thought you would realize yourself, but not yet, so I'll have to give you a little nudge :) .
garry
Posts: 2460
Joined: 22 Dec 2013, 12:50

Re: UTF-8'e Rağmen Karakter Sorunu

23 Sep 2020, 13:50

But I wish I could do it without using the clipboard.
msgbox shows also a variable
here example with a file ( m3u starts music player eg. vlc.exe / or rename as xy.txt )

Code: Select all

#warn
setworkingdir,%a_scriptdir%
Extensions:= "*.mp3`,*.wav`,*.aac"      ;- some music extensions
f1=%a_desktop%\MusicFiles.m3u       ;- here music files from drive D:\
mf:="D:\"
setworkingdir,%MF%
runwait,%comspec% /c dir /b /s %extensions% >"%F1%",,hide
try
 run,%f1%
exitapp
Last edited by garry on 23 Sep 2020, 13:57, edited 1 time in total.
User avatar
hasantr
Posts: 678
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: UTF-8'e Rağmen Karakter Sorunu

23 Sep 2020, 13:57

gregster wrote:
23 Sep 2020, 13:29
@hasantr:would you mind to please translate the topic title to english? ;) Thank you!

I was waiting and thought you would realize yourself, but not yet, so I'll have to give you a little nudge :) .
Seeing the notification I am glad it must have found a gregster solution to the UTF-8 problem. :D
Since Google translate translated all pages, I could not realize it.
Sorry.
User avatar
hasantr
Posts: 678
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: UTF-8'e Rağmen Karakter Sorunu

23 Sep 2020, 14:03

garry wrote:
23 Sep 2020, 13:50
But I wish I could do it without using the clipboard.
msgbox shows also a variable
here example with a file ( m3u starts music player eg. vlc.exe / or rename as xy.txt )

Code: Select all

#warn
setworkingdir,%a_scriptdir%
Extensions:= "*.mp3`,*.wav`,*.aac"      ;- some music extensions
f1=%a_desktop%\MusicFiles.m3u       ;- here music files from drive D:\
mf:="D:\"
setworkingdir,%MF%
runwait,%comspec% /c dir /b /s %extensions% >"%F1%",,hide
try
 run,%f1%
exitapp
Returns a single file. I could not understand how to use this.
gregster
Posts: 5389
Joined: 30 Sep 2013, 06:48

Re: Character Problem Despite UTF-8

23 Sep 2020, 14:04

@hasantr: No problem, thank you for changing it. :thumbup:
But unfortunately, I don't have to contribute anything useful to the actual topic. :shifty:
garry
Posts: 2460
Joined: 22 Dec 2013, 12:50

Re: Character Problem Despite UTF-8

23 Sep 2020, 14:12

Returns a single file. I could not understand how to use this.
maybe it's empty when no files with desired extensions found ( vlc.exe starts xy.m3u file with musicfiles )
here only for files .exe saved to text-file

Code: Select all

;-------- saved at 星期三 九月 2020-09-23  18:50 UTC --------------
;- UTF-8'e Rağmen Karakter Sorunu 
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=81309&p=354227#p354227

#warn
setworkingdir,%a_scriptdir%
;Extensions:= "*.mp3`,*.wav`,*.aac"      ;- some music extensions
Extensions:= "*.exe"
f1=%a_desktop%\FilesEXE_Drive-D.txt
mf:="D:\"
setworkingdir,%MF%
runwait,%comspec% /c dir /b /s %extensions% >"%F1%",,hide
try
 run,%f1%
exitapp
;esc::exitapp
User avatar
hasantr
Posts: 678
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: UTF-8'e Rağmen Karakter Sorunu

23 Sep 2020, 14:30

garry wrote:
23 Sep 2020, 13:50
But I wish I could do it without using the clipboard.
msgbox shows also a variable
here example with a file ( m3u starts music player eg. vlc.exe / or rename as xy.txt )

Code: Select all

#warn
setworkingdir,%a_scriptdir%
Extensions:= "*.mp3`,*.wav`,*.aac"      ;- some music extensions
f1=%a_desktop%\MusicFiles.m3u       ;- here music files from drive D:\
mf:="D:\"
setworkingdir,%MF%
runwait,%comspec% /c dir /b /s %extensions% >"%F1%",,hide
try
 run,%f1%
exitapp
I get it now. Thank you.
Can I exclude some directories? Windows, ProgramFiles etc
garry
Posts: 2460
Joined: 22 Dec 2013, 12:50

Re: Character Problem Despite UTF-8

23 Sep 2020, 15:41

I tried this with built in robocopy , show xy.exe files in drive E:\
EDIT : modified to save as UTF-8 to a textfile ( here in this example searched for xy.mp4 )
- added a 2nd example

Code: Select all

	  			E:\M_CSV\Wouldn't it Be Loverly - Julie Andrews (My Fair Lady )$Cátia Adão$v5ipgrp_xLU.mp4
	  			E:\M_CSV\新妻聖子 Niizuma Seiko 夜来香  Ye Lai Xiang$Habanerotube$UWVn3xA6QL4.mp4

Code: Select all

;- this example lists xy.exe files in drive E:\
;==============================================


src = E:\                                          ;- LIST Drive E for xy.exe files
dst = D:\XX                                        ;- drive exist but not the folder ( for test )
excludex= E:\_BEELINK                              ;- exclude this folder
logfile = %a_desktop%\Robocopy_Log.txt             ;- exclude this file
excludex2=%logfile%                                ;- exclude logfile if it's in source 
ifnotexist,%logfile%
  {
  fileappend,-----`r`n,%logfile%,UTF-8
  sleep,2000
  }
runwait,%comspec% /k robocopy %src% %dst% *.exe /L /S /NDL /NS /NC /NP /XD %excludex% /XF %excludex2% /TEE /UNILOG+:"%logfile%"
exitapp
;=================================================================
2nd Example :

Code: Select all

;- this example lists mp3 and mp4 files in drive E:\
;- and EXCLUDE 2 Folders in drive E:\
;====================================================
extensions:="*.mp3 *.mp4"
transform,s,chr,32
src = E:\                                          ;- LIST Drive E for MP3 and MP4 files
dst = D:\XX                                        ;- drive exist but not the folder ( for test )
excludex=                                          ;- EXCLUDE these folders
(Ltrim join%s%
E:\_BEELINK                              
E:\M_CSV
)
logfile = %a_desktop%\Robocopy_Log.txt             ;- exclude this file
excludex2=%logfile%                                ;- exclude logfile if it's in source 
ifnotexist,%logfile%
  {
  fileappend,-----`r`n,%logfile%,UTF-8
  sleep,2000
  }
runwait,%comspec% /k robocopy %src% %dst% %extensions% /L /S /NDL /NS /NC /NP /XD %excludex% /XF %excludex2% /TEE /UNILOG+:"%logfile%"
exitapp
;=================================================================
User avatar
Smile_
Posts: 306
Joined: 03 May 2020, 00:51

Re: Character Problem Despite UTF-8

24 Sep 2020, 03:29

@hasantr

Code: Select all

List := ""
Extensions := "docx,pdf,odf,rtf,exe"
Loop, Files, D:\*.*, R
    If InStr(Extensions, A_LoopFileExt)
        List .= A_LoopFileFullPath "`n"
MsgBox %List%
User avatar
hasantr
Posts: 678
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Character Problem Despite UTF-8

24 Sep 2020, 05:35

Thanks friends. I will run speed tests and use one of these methods. I couldn't find the source of the problem with runcmd.
garry
Posts: 2460
Joined: 22 Dec 2013, 12:50

Re: Character Problem Despite UTF-8

24 Sep 2020, 08:13

xcopy LIST with EXCLUDE folders
EDIT : Problem with UTF-8

Code: Select all

#warn
setworkingdir,%a_scriptdir%
;-----------------------------------
exclude= 
(Ltrim Join`r`n
C:\Users
%a_windir%
%a_programfiles%
C:\$Recycle.Bin
)
;-----------------------------------
F0=%a_scriptdir%\Liste_EXE-Files.txt
ifexist,%f0%
  filedelete,%f0%
F1=Exclusion_List.txt 
ifnotexist,%f1%
  fileappend,`r`n%exclude%`r`n,%f1%
;-----------------------------------
runwait,%comspec% /c xcopy c:\*.exe d:\ /L /S /exclude:%f1% >%f0%,,hide     ;- if add parameter /H see hidden files
runwait,%comspec% /c xcopy c:\*.ini d:\ /L /S /exclude:%f1% >>%f0%,,hide
;-----------------------------------
ifexist,%f0%
 {
 try
   run,%f0%
 }
exitapp
esc::exitapp
;=======================================================================

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], mikeyww, teadrinker and 31 guests