Ich brauche alle Wörter nach split[8]

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

effel
Posts: 555
Joined: 16 Jan 2018, 13:34

Ich brauche alle Wörter nach split[8]

Post by effel » 18 Apr 2023, 00:15

Hallo AHK Gemeinde

Mit folgendem FTP Script greife ich auf meine Fritz Box zu.

Code: Select all

#Persistent
SetWorkingDir %A_ScriptDir%
startZeit := A_TickCount
FTPCommandFile = FTPCommands.txt
FTPLogFile     = FTP.log

FileAppend,
(
open xxxxxxxxxxxxxx.myfritz.net
username
passwort
cd "/JMicron-Generic-01/TMP-Test-Verzeichnis"
dir
binary
get "220304_abgezockt_container_skandal_inf_3360k_p36v15.mp4"
bye
), %FTPCommandFile%

 Run, cmd /k ftp -s:%FTPCommandFile% > %FTPLogFile%,,Hide
 Process, wait, cmd.exe
 PID := ErrorLevel
 if PID
 setTimer, Fertig, -1
return

   Fertig:
	If FileExist(FTPLogFile) {
	FileRead thisLog,% FTPLogFile
		if thisLog contains 221 Goodbye
		{
		 Filedelete, %FTPCommandFile%
		 FormatTime, TimeStamp,% a_now, dd.MM.yyyy HH-mm-ss tt
		 FileMove,% FTPLogFile,% TimeStamp "  -  " FTPLogFile
		 Process, Close, %PID%
		 EndZeit := (A_TickCount - StartZeit) / 1000
		 FileAppend,% "`nDownloadZeit:`t" round(EndZeit) " Sekunden",% TimeStamp "  -  " FTPLogFile
		 exitapp
		}}
	 setTimer, Fertig, -100
   return

Das läuft auch alles wie gedacht. Nun möchte ich es durch eine GUI erweitern. Dabei sollen die via Dir Befehl angezeigten Files in einem ListView angezeigt werden.

Um die FileNamen zu bekommen plane ich so vorzugehen:

Code: Select all

;FileRead, logFile, ftp.log
logFile := "-rwxrwxrwx 1 ftp ftp 863293667 Apr 10 20:44 220304_abgezockt_container_skandal_inf_3360k_p36v15.mp4`n"
logFile .= "-rwxrwxrwx 1 ftp ftp 0 Apr 11 04:51 test eins zwei drei vier fünf sechs sieben.txt`n"
logFile .= "-rwxrwxrwx 1 ftp ftp 0 Apr 11 04:51 a b c d e f g.xlsx`n"


	    loop, parse, logFile, "`n", "`r"
		{
			if a_loopfield contains -rwxrwxrwx
			{
			split := strSplit(a_loopfield, a_space)
			resultat .= split[9] a_space 
				  . split.10 a_space 
				  . split.11 a_space 
				  . split.12 a_space 
				  . split.13 a_space 
				  . split.14 a_space 
				  . split.15 a_space 
				  . split.16 a_space 
				  . split.17 "`n" 
				  . ((split.length())-8)  "`n" 
			}
		}
	MsgBox,,% A_LineNumber,% resultat "`n" 

Wie bekomme ich den FileNamen ohne schätzen heraus?

Ich brauche alle Wörter nach split[8]
just me
Posts: 9574
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Ich brauche alle Wörter nach split[8]

Post by just me » 18 Apr 2023, 03:24

Moin @effel,

Code: Select all

Array := StrSplit(Zkette , Trennzeichen, WegzulassendeZeichen, MaxParts)
das Zauberwort ist in diesem Fall MaxParts.

Code: Select all

logFile := "-rwxrwxrwx 1 ftp ftp 863293667 Apr 10 20:44 220304_abgezockt_container_skandal_inf_3360k_p36v15.mp4`n"
logFile .= "-rwxrwxrwx 1 ftp ftp 0 Apr 11 04:51 test eins zwei drei vier fünf sechs sieben.txt`n"
logFile .= "-rwxrwxrwx 1 ftp ftp 0 Apr 11 04:51 a b c d e f g.xlsx`n"

DateiAnzahl := 0
Loop, Parse, logFile, `n, `r
{
   Split := StrSplit(A_LoopField, " ", , 9) ; maximal 9 Teile
   If (Split.Length() = 9)
      MsgBox, 0, % "Datei " . ++DateiAnzahl, % Split[9]
}
garry
Posts: 3795
Joined: 22 Dec 2013, 12:50

Re: Ich brauche alle Wörter nach split[8]

Post by garry » 18 Apr 2023, 09:20

@just me danke ( habe lediglich anders dargestellt )

Code: Select all

;-Array := StrSplit(Zkette , Trennzeichen, WegzulassendeZeichen, MaxParts)
dlm:=" "
e1=
(
-rwxrwxrwx 1 ftp ftp 863293667 Apr 10 20:44 220304_abgezockt_container_skandal_inf_3360k_p36v15.mp4
-rwxrwxrwx 1 ftp ftp 0 Apr 11 04:51 test eins zwei drei vier fünf sechs sieben.txt
-rwxrwxrwx 1 ftp ftp 0 Apr 11 04:51 a b c d e f g.xlsx
)
Loop, Parse,e1, `n, `r
{
h := StrSplit(A_LoopField,dlm,,9)
If (h.Length() = 9)
  v .= h[9] . "`r`n"  
}
msgbox,%v%
exitapp
effel
Posts: 555
Joined: 16 Jan 2018, 13:34

Re: Ich brauche alle Wörter nach split[8]

Post by effel » 18 Apr 2023, 13:27

Hallo Just Me, ich mag es wenn du zauberst, danke

Es ist zum Haare raufen, habe bis jetzt schon etliche ListView in meinen Scripten etabliert, aber bei diesem bin ich grade am Ende meiner kläglichen Programmierkunst angelangt.

Ich bekomme die Daten nicht ins ListView. Habe den Code einige viele male umgestellt, verändert und ärgere mich jetzt schon darüber das die Lösung sicher sehr einfach ist... ;)

Nur dieser eine Eintrag wird angezeigt LV_Add("", 1, "test")

Code: Select all

#Persistent
#SingleInstance Force
FileEncoding, UTF-8
SetBatchLines, -1
SetTitleMatchMode, 2
SetWorkingDir %A_ScriptDir%
startZeit := A_TickCount
FTPCommandFile = FTPCommands.txt
FTPLogFile     = FTP.log

Gui, New, +hwndhGUIA +E0x20
Gui, Font, 	s10
Gui, Add, Tab3,,Home|Statistik
Gui, Tab, 1
Gui, Add, ListView,% "w" A_ScreenWidth-430 " r20 vLV +LV0x00010000 Section", #|Liste
Gui, Add, Button, Section w160 gEditScript,% Chr(0xE115) " Edit Script"
Gui, Add, Button, ys w160 gClearListView, ClearListView
;Gui, Tab, 2
Gui, Show,% " w" A_ScreenWidth-380 " h" A_ScreenHeight-450,% a_scriptName
GuiControl , Choose , systabcontrol321 , 1

FileAppend,
(
open xxxxxxxxxxxxxxx.myfritz.net
username
passwort
cd "/JMicron-Generic-01/Serien"
dir
cd "/JMicron-Generic-01/filme"
dir
bye
), %FTPCommandFile%

 Run, cmd /k ftp -s:%FTPCommandFile% > %FTPLogFile%,,Hide
 Process, wait, cmd.exe
 PID := ErrorLevel
 if PID
 setTimer, isDone, -1
		LV_Add("", 1, "test")
return

   isDone:
	If FileExist(FTPLogFile) {
	FileRead thisLog,% FTPLogFile
		if thisLog contains 221 Goodbye
		{
		 Filedelete, %FTPCommandFile%
		 FormatTime, TimeStamp,% a_now, dd.MM.yyyy HH-mm-ss tt
		 FileMove,% FTPLogFile,% TimeStamp "  -  " FTPLogFile
		 Process, Close, %PID%
		 EndZeit := (A_TickCount - StartZeit) / 1000
		 FileAppend,% "`nDownloadZeit:`t" round(EndZeit) " Sekunden",% TimeStamp "  -  " FTPLogFile
		 goto getFileList
		}}
	 setTimer, isDone, -100
   return


   getFileList:
	res     := ""
	counter := 0
	test    := 0
	if fileExist(TimeStamp "  -  " FTPLogFile)
	{
	fileRead, logFile,% (TimeStamp "  -  " FTPLogFile)
	  Loop, Parse, logFile, `n, `r
	  {
	  if a_loopfield contains wxrwxrwx
	    {
	     Split := StrSplit(A_LoopField, " ", , 9) ; maximal 9 Teile
	     If (Split.Length() = 9)
		{
	        res .= Split[9] "`n"
		counter++
	     }}}
	}
	;	GuiControl, -ReDraw, LV
		for i, v in strSplit(res, "`n", "`r")
		 {
		  if v
		   {
		    LV_Add("", i, v)
		    test .= i a_space v "`n"
		   }}
		Loop, % LV_GetCount("Columns")
		LV_ModifyCol(A_Index, "AutoHdr")
	;	GuiControl, +Redraw, LV
               MsgBox,,% counter, % res
               MsgBox,,% counter, % test
   return


; -rwxrwxrwx Files
; drwxrwxrwx  verzeichnisse


EditScript:
try run, notepad.exe %A_ScriptName%
return

ClearListView:
LV_Delete()
return

Dann habe ich auch Probleme mit dem Zeichensatz. Ü wird hier nicht ordnungsgemäß verarbeitet.

Es macht auch keinen Sinn wenn ich FileEncoding, UTF-8 nutze, auch der Versuch fileRead, logFile,% (TimeStamp " - " FTPLogFile), UTF-8 verläuft furchtlos.

In der Hilfe von Command.com finde ich zwar eine Möglichkeit die CodePage zu beeinflussen, weiß aber nicht wie ich das in den Run Befehl integrieren soll

In der Hilfe von FTP sehe ich keine Optionen.

Als letzten meiner Versuche habe ich FTPLogFile = FTP.log, UTF-8 getestet...

Das von Run, cmd /k ftp -s:%FTPCommandFile% > %FTPLogFile%,,Hide geschriebene Text File ist und bleibt im Ansi Format

Ausschnitt vom ScreenCopy der MsgBox:
04_18_23 @7_02_30.PNG
04_18_23 @7_02_30.PNG (4.23 KiB) Viewed 662 times

04_18_23 @7_42_01.PNG
04_18_23 @7_42_01.PNG (28.92 KiB) Viewed 662 times


Hallo @garry, ich musste heute morgen eine Stunde warten, bis ich diesen Thread posten konnte, dauernd war der Server nicht erreichbar, hast du etwa deinen Rechner heute Nacht wieder angelassen? :monkeysay:

Läuft deine ChatGPT Version jetzt zu deiner Zufriedenheit?

Gruß aus Köln
garry
Posts: 3795
Joined: 22 Dec 2013, 12:50

Re: Ich brauche alle Wörter nach split[8]

Post by garry » 18 Apr 2023, 15:15

hello @effel Dein Skript (z.B. ChatGPT ) läuft einwandfrei , entschuldige für Verwirrung
.. dauernd war der Server nicht erreichbar, hast du etwa deinen Rechner heute Nacht wieder angelassen?

... neee gehe meistens nach 22:00 ins Bett ... :)

hier nur kurz ein Beispiel mit DOS command 'dir' um special Characters darzustellen ( evtl für betreff > Run, cmd /k ftp -s:%FTPCommandFile% > %FTPLogFile%,,Hide )

Code: Select all

;- example read file names like > Åäöü 夜来香 เย่ไหลเซียง_Ye Lai Xiang$Bkkjay Th$zS6jOzNty1M.txt
F1  :=a_scriptdir . "\dir_german_chinese.txt"
F2  :=a_scriptdir . "\NEW.txt"
cmdx:="dir"     ;- DOS command
;---------
RunWait, %Comspec% /U /C (%cmdx%) 2>&1 >%f1%,, Hide   ;- file F1 is UTF-16 LE
FileRead,text1, *P1200 %f1%                           ;- read F1 
msgbox,%text1%
Fileappend,%text1%,%f2%,utf-8                         ;- file F2 is UTF-8 with BOM
try run,"%f2%"
return
;=========
effel
Posts: 555
Joined: 16 Jan 2018, 13:34

Re: Ich brauche alle Wörter nach split[8]

Post by effel » 19 Apr 2023, 02:51

jetzt läufts, danke fürs verweilen

Code: Select all

ANow := A_Now
If !FileExist(A_ScriptDir "\save\")
FileCreateDir,% A_ScriptDir "\save\"
FileCopy, % A_ScriptFullPath, % A_ScriptDir "\save\" A_ScriptName " save " A_Now " .ahk"


#Persistent
#SingleInstance Force
FileEncoding, UTF-8
SetWorkingDir %A_ScriptDir%
startZeit := A_TickCount
FTPCommandFile = FTPCommands.txt
FTPLogFile     = FTP.log
thisLoad        := false

Gui, New, +hwndhGUIA +E0x20 ; +AlwaysOnTop +Owner +LastFound +Border +Caption +Resize -ToolWindow, control
Gui, Font, 	s10
Gui, Add, Tab3,,Home|Statistik
Gui, Tab, 1
Gui, Add, ListView,% "w" A_ScreenWidth-430 " r20 vLV +LV0x00010000 Section", #|1|2|3|4|5|6|7|8|9
Gui, Add, Button, Section w160 gEditScript,% Chr(0xE115) " Edit Script"
Gui, Add, Button, ys w160 gClearListView, Reload FTP Daten
;Gui, Tab, 2
Gui, Show,% " w" A_ScreenWidth-380 " h" A_ScreenHeight-450,% a_scriptName
GuiControl , Choose , systabcontrol321 , 1

StartAgain:
FileAppend,
(
open xxxxxxxxx.myfritz.net
user
pass
cd "/JMicron-Generic-01/Doreen/Serien"
dir
cd "/JMicron-Generic-01/Doreen/filme"
dir
bye
), %FTPCommandFile%

 Run, cmd /k ftp -s:%FTPCommandFile% > %FTPLogFile%,,Hide
 Process, wait, cmd.exe
 PID := ErrorLevel
 if PID
 setTimer, isDone, -1
tooltip % thisLoad 
sleep, 2000
LV_Delete()
thisFirst := StartReloadLV(logFile)
return

;binary
;get "220304_abgezockt_container_skandal_inf_3360k_p36v15.mp4"


   isDone:
	If FileExist(FTPLogFile) {
	FileRead thisLog,% FTPLogFile
		if thisLog contains 221 Goodbye
		{
		 Filedelete, %FTPCommandFile%
		 FormatTime, TimeStamp,% a_now, dd.MM.yyyy HH-mm-ss tt
		 FileMove,% FTPLogFile,% TimeStamp "  -  " FTPLogFile
		 Process, Close, %PID%
		 EndZeit := (A_TickCount - StartZeit) / 1000
		 FileAppend,% "`nDownloadZeit:`t" round(EndZeit) " Sekunden",% TimeStamp "  -  " FTPLogFile, UTF-8
		 goto getFileList
		}}
	 setTimer, isDone, -100

   return


   getFileList:
	res     := ""
	counter := 0
	test    := 0
filesCounter    := 0
folderCounter   := 0
	if fileExist(TimeStamp "  -  " FTPLogFile)
	{
	fileRead, logFile,% (TimeStamp "  -  " FTPLogFile)       
	  Loop, Parse, logFile, `n, `r
	  {
	  if a_loopfield contains wxrwxrwx
	    {
	     Split := StrSplit(A_LoopField, " ", , 9) ; maximal 9 Teile
	     xSplit := StrSplit(A_LoopField, a_space)
	     If (Split.Length() = 9)
		{
		  counter++
		split1 :=  xSplit[1]
		split2 :=  xSplit[2]
		split3 :=  xSplit[3]
		split4 :=  xSplit[4]
		split5 :=  xSplit[5]
		split6 :=  xSplit[6]
		split7 :=  xSplit[7]
		split8 :=  xSplit[8]
		split9 :=   Split[9]
		if split1 contains -rwxrwxrwx
		  filesCounter++
		if split1 contains drwxrwxrwx
		  folderCounter++
	        res .= Split[9] "`n"
	     }}}
	}
;               MsgBox,,% "filesCounter:`t" filesCounter "`t - `tfolderCounter:`n" folderCounter "`t - `tGesamt:`t" counter , % res
   return

StartReloadLV(logFile) {
	  LV_Delete()
	  Loop, Parse, logFile, `n, `r
	  {
	  if a_loopfield contains wxrwxrwx
	    {
	     Split := StrSplit(A_LoopField, " ", , 9) ; maximal 9 Teile
	     xSplit := StrSplit(A_LoopField, a_space)
	     If (Split.Length() = 9)
		{
;		 LV_Add("", a_index, split1, split2, split3, split4, split5, split6, split7, split.8, split.9)
		 LV_Add("", a_index, split.1, split.2, split.3, split.4, split.5, split.6, split.7, split.8, split.9)
		Loop, % LV_GetCount("Columns")
		LV_ModifyCol(A_Index, "AutoHdr")
			}}}

}


; -rwxrwxrwx Files
; drwxrwxrwx  verzeichnisse


EditScript:
try run, notepad.exe %A_ScriptName%
return

ClearListView:
LV_Delete()
gosub StartAgain
thisFirst := StartReloadLV(logFile)
return

04_19_23 @9_48_21.PNG
04_19_23 @9_48_21.PNG (45.31 KiB) Viewed 626 times
just me
Posts: 9574
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Ich brauche alle Wörter nach split[8]

Post by just me » 19 Apr 2023, 03:45

Moin @effel,

zum Thema Zeichensatz:

Die Dateiliste entsteht, indem die DOS-Bildschirmausgabe in eine Datei umgeleitet wird. Der im CMD-Fenster verwendete Zeichensatz steht im Bild in viewtopic.php?p=518120#p518120 : 850. Du kannst deshalb mal versuchen, die Datei mit FileRead, logFile,% ("*P850 " TimeStamp " - " FTPLogFile) einzulesen.

Ansonsten:
Wenn Du alle Elemente eines Arrays aufeinanderfolgend am Ende einer ListView-Zeile einfügen willst, geht das auch so

Code: Select all

LV_Add("", A_Index, Split*)
Und wenn Du statt Contains die Funktion InStr() nutzt, kannst Du damit Arrayelemente auch direkt ansprechen:

Code: Select all

If InStr(Split[1], "-rwxrwxrwx")
.
effel
Posts: 555
Joined: 16 Jan 2018, 13:34

Re: Ich brauche alle Wörter nach split[8]

Post by effel » 19 Apr 2023, 16:56

just me wrote:
19 Apr 2023, 03:45
FileRead, logFile,% ("*P850 " TimeStamp " - " FTPLogFile)
das Logfile bleibt leer.

Ich habe ein Verzeichnis im NAS angelegt test ÄÜßÖ

im logfile steht es dann so: dr-xr-xr-x 2 ftp ftp 32768 Apr 19 23:45 test Žšá™
Spoiler
04_19_23 @11_49_22.PNG
04_19_23 @11_49_22.PNG (42.03 KiB) Viewed 589 times
just me
Posts: 9574
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Ich brauche alle Wörter nach split[8]

Post by just me » 20 Apr 2023, 03:49

Moin,

das kommt davon, wenn man seine Dateinamen mit Leerzeichen aufhübscht. Du hast vor und nach dem Bindestrich anscheinend zwei davon:

Code: Select all

	fileRead, logFile,% (TimeStamp "  -  " FTPLogFile)      
Dehalb: Du kannst versuchen, der FileRead-Anweisung die Option *P850 hinzuzufügen.
effel
Posts: 555
Joined: 16 Jan 2018, 13:34

Re: Ich brauche alle Wörter nach split[8]

Post by effel » 20 Apr 2023, 04:32

just me wrote:
20 Apr 2023, 03:49
die Option *P850 hinzuzufügen.
Hallo Just Me

Das war genau richtig und sieht gut aus.

Dankeschön

04_20_23 @11_17_48.PNG
04_20_23 @11_17_48.PNG (47.1 KiB) Viewed 577 times

Im Original Text des Fritz LogFiles entdeckte ich verschiedene Schreibweisen für "successful". Lustig das es bei den Fritz Codern noch niemand bemerkt und behoben hat. 250 CWD command successful.
ftp> dir
200 EPRT command sucessful.
Ahk_fan
Posts: 238
Joined: 31 Aug 2018, 14:34
Contact:

Re: Ich brauche alle Wörter nach split[8]

Post by Ahk_fan » 20 Apr 2023, 15:54

hier gibt es eine sehr nützliche Funktion: viewtopic.php?t=74647 --> RunCMD
Da gibt man den Inhalt der Console in eine Variable und kann es gut weiterverarbeiten...man kann auch die Codepages mitgeben
regards,
AHK_fan :)
https://hr-anwendungen.de
Post Reply

Return to “Ich brauche Hilfe”