Alle Ordner(pfade) in eine Datei schreiber!

  • Hallo
    ich hab noch kein so ein Programm bis jetzt gesehen und da ich noch nicht so lange mit AutoIt zu tun habe, habe ich einfach dieses Werk programmiert:

    es schreibt alle Unterordner eines Pfades in eine ini Datei! (Warum ini datei? ich wusste nicht was am besten wäre und darum nam ich die ini datei her da meine überlegungen auf die schnelle keine einfachere lösung fanden :))

    ich habe für 30014 Ordner auf meiner C Festplatte mit 26Gb belegten speicher platz in etwa 5,5 Minuten gebraucht, damit alle ordner in die Ini datei geschrieben wurden!


    ich hoffe euch gefällt mein script und ich hoffe das es Verbesserungsvorschläge gibt, aber auch etwas Lob :)


    Spoiler anzeigen
    [autoit]

    #cs ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    AutoIt Version: 3.3.6.1
    Author: Sturmberger Andreas

    [/autoit] [autoit][/autoit] [autoit]

    Script Function:
    Saves the whole foldertree of a drive or folder into an inifile

    [/autoit] [autoit][/autoit] [autoit]

    #ce ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    Func _FileListToArray($sPath, $sFilter = "*", $iFlag = 0)
    Local $hSearch, $sFile, $sFileList, $sDelim = "|"
    ;$sPath = StringRegExpReplace($sPath, "[\\/]+\z", "") & "\" ; ensure single trailing backslash
    ;If Not FileExists($sPath) Then Return SetError(1, 1, "")
    ;If StringRegExp($sFilter, "[\\/:><\|]|(?s)\A\s*\z") Then Return SetError(2, 2, "")
    ;If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
    $hSearch = FileFindFirstFile($sPath & $sFilter)
    ;If @error Then Return SetError(4, 4, "")
    While 1
    $sFile = FileFindNextFile($hSearch)
    If @error Then ExitLoop
    If ($iFlag + @extended = 2) Then ContinueLoop
    $sFileList &= $sDelim & $sFile
    WEnd
    FileClose($hSearch)
    ;If Not $sFileList Then Return SetError(4, 4, "")
    Return StringSplit(StringTrimLeft($sFileList, 1), "|")
    EndFunc
    #cs ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    I included the _FileListToArray here and not with #include <file.au3> because it made some troubles!
    I simply commented all unneeded comments

    [/autoit] [autoit][/autoit] [autoit]

    #ce ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Dim $path = "C:\"
    Dim $instance = 0
    Dim $inipath = "C:\paths.ini"
    Dim $tempfiles
    Dim $tempdir
    Dim $filescount
    Dim $count = 1
    $files = _FileListToArray($path, "*", 2) ;saves the first instance into the array

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    IniWrite ($inipath, "instance " & $instance, "files", $files[0]) ;writes the numbers of containing folders in the root to the ini file
    For $i = 1 to $files[0]
    IniWrite ($inipath, "instance " & $instance, "path" & $i, $path & $files[$i]) ; writes the path of the folders into the ini file while the first folder is path1, the second path2, the n pathn
    Next
    Do
    $bool = false ;is needed to stop the loop
    $instance += 1 ;counts the instance

    [/autoit] [autoit][/autoit] [autoit]

    $tempfiles = IniRead($inipath, "instance " & $instance - 1, "files", "Fehler") ;var which contains the number of the containing folders of the next lower instance
    for $i = 1 to $tempfiles ;counts from 1 to the number of the containing folder of the next lower instance
    $tempdir = IniRead($inipath, "instance " & $instance - 1, "path" & $i, "Fehler") & "\" ;var which contains the path of the "$i"-folder of the next lower instance
    $files = _FileListToArray($tempdir, "*", 2) ;saves the folders of the path of $tempdir
    $filescount += $files[0] ;counts how many folders contained in the folder of $tempdir
    ;Write to inifile
    For $j = 1 to $files[0] ; counts from 1 to the number of folders contained in $tempdir
    If $files[$j] <> "" Then ;some folders can't be accessed or are simply the last folder of the instance
    IniWrite ($inipath, "instance " & $instance, "path" & $count, $tempdir & $files[$j]) ;writes the path of the folders into the ini file while the first folder is path1, the second path2, the n pathn
    $count += 1 ;counter so we know which path? is needed
    $bool = true ;if there are no more folders to access $bool will stay false and it will end the loop
    EndIf
    Next
    ;end write to inifile
    Next
    IniWrite ($inipath, "instance " & $instance, "files", $count - 1) ;writes the number of folders in the 2nd instance
    if $count = 1 Then iniDelete($inipath, "instance " & $instance) ;if the count doest increase it means the last instance was the instance before this 1. so the last distance made has to be deleteg again
    $count = 1 ;resets the count to 1

    Until $bool = false

    [/autoit]
    • Offizieller Beitrag

    Versuch mal sowas.

    Spoiler anzeigen
    [autoit]

    #include <Array.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $StartPfad = 'c:\'
    Global $FileTyp = '*'
    $aFiles = _GetFilesFolder_Rekursiv($StartPfad, $FileTyp, 1)

    [/autoit] [autoit][/autoit] [autoit]

    _ArrayDisplay($aFiles)

    [/autoit] [autoit][/autoit] [autoit]

    ;==================================================================================================
    ; Function Name: _GetFilesFolder_Rekursiv($sPath [, $sExt='*' [, $iDir=-1 [, $iRetType=0 ,[$sDelim='0']]]])
    ; Description: Rekursive Auflistung von Dateien und/oder Ordnern
    ; Parameter(s): $sPath der Basispfad für die Auflistung ('.' -aktueller Pfad, '..' -Parentpfad)
    ; $sExt Erweiterung für Dateiauswahl '*' oder -1 für alle (Standard)
    ; $iDir -1 Dateien+Ordner(Standard), 0 nur Dateien, 1 nur Ordner
    ; optional: $iRetType 0 gibt Array, 1 gibt String zurück
    ; optional: $sDelim legt Trennzeichen für Stringrückgabe fest
    ; 0 -@CRLF (Standard); 1 -@CR; 2 -@LF; oder beliebiges Zeichen
    ; Return Value(s): Array (Standard) od. String mit den gefundenen Pfaden der Dateien und/oder Ordner
    ; Array[0] enthält die Anzahl der gefundenen Dateien/Ordner
    ; Author(s): BugFix ([email='bugfix@autoit.de'][/email])
    ;==================================================================================================
    Func _GetFilesFolder_Rekursiv($sPath, $sExt = '*', $iDir = -1, $iRetType = 0, $sDelim = '0')
    Global $oFSO = ObjCreate('Scripting.FileSystemObject')
    Global $strFiles = ''
    Switch $sDelim
    Case '1'
    $sDelim = @CR
    Case '2'
    $sDelim = @LF
    Case Else
    $sDelim = @CRLF
    EndSwitch
    If ($iRetType < 0) Or ($iRetType > 1) Then $iRetType = 0
    If $sExt = -1 Then $sExt = '*'
    If ($iDir < -1) Or ($iDir > 1) Then $iDir = -1
    _ShowSubFolders($oFSO.GetFolder($sPath), $sExt, $iDir, $sDelim)
    If $iRetType = 0 Then
    Local $aOut
    ;~ $aOut = StringSplit(StringTrimRight($strFiles, 1), $sDelim, 1)
    $aOut = StringSplit(StringStripWS($strFiles, 2), $sDelim, 1)
    If $aOut[1] = '' Then
    ReDim $aOut[1]
    $aOut[0] = 0
    EndIf
    Return $aOut
    Else
    ;~ Return StringTrimRight($strFiles, 1)
    Return StringStripWS($strFiles, 2)
    EndIf
    EndFunc ;==>_GetFilesFolder_Rekursiv

    [/autoit] [autoit][/autoit] [autoit]

    Func _ShowSubFolders($Folder, $Ext = '*', $Dir = -1, $Delim = @CRLF)
    If Not IsDeclared("strFiles") Then Global $strFiles = ''
    If ($Dir = -1) Or ($Dir = 0) Then
    For $file In $Folder.Files
    If $Ext <> '*' Then
    If StringRight($file.Name, StringLen($Ext)) = $Ext Then _
    $strFiles &= $file.Path & $Delim
    Else
    $strFiles &= $file.Path & $Delim
    EndIf
    Next
    EndIf
    For $Subfolder In $Folder.SubFolders
    If ($Dir = -1) Or ($Dir = 1) Then $strFiles &= $Subfolder.Path & '\' & $Delim
    _ShowSubFolders($Subfolder, $Ext, $Dir, $Delim)
    Next
    EndFunc ;==>_ShowSubFolders

    [/autoit]

    Mega