knolle93 Posted August 3, 2018 Posted August 3, 2018 Hello Guys, since english is not my native language i will try my best to explain my problem. I want to create a Script which scans all folders in its directory and counts the files in the Folders and returns a 2d array which somehow looks like this FolderName1 320 FolderName2 12 FolderName3 2 FolderName4 4330 FolderName5 0 FolderName6 20 This is everything i tried til now and im not happy with it, first i tried to write files with contents then i tried to make an array and parse the content into an .ini file but it failed as well, also i cant get the 2d array which i talked about in the first place done Spoiler expandcollapse popup;Dreizeiler der Verhindert, das dieses Programm in jeder Ordnerstruktur angewendet werden kann. $Pfad = @ScriptDir $Sicherung = StringInStr($Pfad,"Umzug") If $Sicherung = 0 Then Exit ;~ alle dateien mit der endung .dat aus dem Umzugshelper löschen! FileDelete(@Scriptdir & "\Umzugshelper\*.dat") FileDelete(@Scriptdir & "\Umzugshelper\days\*.dat") if FileExists(@Scriptdir & "\Umzugshelper\*.dat") = 0 Then DirCreate(@Scriptdir & "\Umzugshelper") EndIf if FileExists(@Scriptdir & "\Umzugshelper\days\*.dat") = 0 Then DirCreate(@Scriptdir & "\Umzugshelper\days") EndIf #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> $contentsdays = @ScriptDir & "\Umzugshelper" & "\contentsdays.dat" ;~ Schreibe Array über alle Ordner (FLAG 2) in eine Datei $Contentsdays Local $aFileList = _FileListToArray(@ScriptDir, "*",2) _ArrayDisplay($aFileList) IniWriteSection(@Scriptdir&"\test.ini","Data",$aFileList) MsgBox(0,"",@Scriptdir&"\test.ini") _FileWriteFromArray($contentsdays,$aFileList) ;~ Countvar $i = 1 $DayVar = "" ;~ Infinite Loop while FileReadLine($contentsdays, $i) not 0 While 1 ;~ Break If FileReadLine($contentsdays, $i) = "" Then ExitLoop ;~ Prozedur und autom hochzählen kopfgesteuert Else $DayVar = FileReadLine($contentsdays, $i) $aFileList2 = DirGetSize(@Scriptdir&"\"&$DayVar,1) $contentsitems = @ScriptDir & "\Umzugshelper\days\" & $DayVar & ".dat" _FileWriteFromArray($contentsitems,$aFileList2) $i = $i + 1 EndIf WEnd ;~ While 1 ;~ WEnd i hope u can give me a push towards the right direction! best regards!
knolle93 Posted August 4, 2018 Author Posted August 4, 2018 I restarted the whole thing and got to the point where i could write the array as i want it to an .ini file is there a way to make a 2d array out of an ini section? #include <File.au3> #include <Array.au3> $i = 1 $OrdnerInhalte = _FileListToArray(@ScriptDir,"*",2) While 1 If $i >= $OrdnerInhalte[0] Then ExitLoop EndIf ;~ MsgBox(64,"Debug",@ScriptDir&"\"&$AnzahlDateien[0]) ;~ $AnzahlDateien = _FileListToArray(@ScriptDir&"\"&$OrdnerInhalte[$i],"*",1) ;~ ConsoleWrite($i&@CRLF) ;~ ConsoleWrite($OrdnerInhalte[$i]&@CRLF MsgBox(64,"",@ScriptDir&"\"&$OrdnerInhalte[$i]) $DirWA = DirGetSize(@ScriptDir&"\"&$OrdnerInhalte[$i],1) IniWrite(@Scriptdir&"\ini.ini","Daten",$Ordnerinhalte[$i],$DirWA[1]) $i = $i + 1 ;~ _ArrayDisplay($AnzahlDateien) WEnd
knolle93 Posted August 4, 2018 Author Posted August 4, 2018 Problem solved. #include <File.au3> #include <Array.au3> CreateBelegungsliste() _ArrayDisplay($Belegungsliste) Func CreateBelegungsliste() $inifile = @Scriptdir&"\data.ini" $i = 1 $OrdnerInhalte = _FileListToArray(@ScriptDir,"*",2) While 1 If $i >= $OrdnerInhalte[0] Then ExitLoop EndIf $DirWA = DirGetSize(@ScriptDir&"\"&$OrdnerInhalte[$i],1) IniWrite($inifile,"Daten",$Ordnerinhalte[$i],$DirWA[1]) $i = $i + 1 WEnd Global $Belegungsliste = IniReadSection($inifile,"Daten") EndFunc
Simpel Posted August 4, 2018 Posted August 4, 2018 Hi. Maybe you can use this if you don't need an ini: #include <File.au3> #include <FileConstants.au3> #include <AutoItConstants.au3> #include <Array.au3> Local $aResultat = CreateBelegungsliste() ; assign function to a variable _ArrayDisplay($aResultat) ; display that variable Func CreateBelegungsliste() Local $aOrdnerPfadeUndAnzahlFiles[0][2] ; temporary array including pathes and file counter - [0][2] 0 rows and 2 columns Local $aOrdnerPfade = _FileListToArray(@ScriptDir, "*", $FLTA_FOLDERS) ; avoid magic numbers use constants instead - but youhave to include these contants at the top of the script If @error Then Return SetError(1, @error, 0) ; look if there is an error and return the error as extended Local $aDirWA ; declare variable outside a loop For $i = 1 To $aOrdnerPfade[0] ; shorter then while wend and stops automatically when array ends $aDirWA = DirGetSize(@ScriptDir & "\" & $aOrdnerPfade[$i], $DIR_EXTENDED) ; again avoid magic number - it's better to read _ArrayAdd($aOrdnerPfadeUndAnzahlFiles, $aOrdnerPfade[$i] & "|" & $aDirWA[1]) ; appends folder and ffile counter to temporary array Next _ArrayInsert($aOrdnerPfadeUndAnzahlFiles, 0, UBound($aOrdnerPfadeUndAnzahlFiles)) ; inserts the amount of rows in the first line of the temporary array Return $aOrdnerPfadeUndAnzahlFiles ; returns the temporary array EndFunc I added a lot of comments just to show you why I did this. I suggest to read the best coding practices (https://www.autoitscript.com/wiki/Best_coding_practices). Then you understand why my variable looks like they do. Regards, Simpel SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now