Dead Posted July 28, 2008 Share Posted July 28, 2008 This script scans selected directory then continues to scan all sub directories and stores File/Folder names in an SQLite database Database required for large amounts of files Tested on 2302 Files/Folders requires Autoit Beta expandcollapse popup#include <Array.au3> #include <File.au3> #include <sqlite.au3> #include <sqlite.dll.au3> $Database = @ScriptDir & "\Dir_Recurse.sqlite" If FileExists($Database) = 0 Then; Automatically creates SQLite database _FileCreate($Database) _SQLite_Startup() _SQLite_Open($Database) _SQLite_Exec(-1, "Create table IF NOT EXISTS dir (dir BLOB);") _SQLite_Close() _SQLite_Shutdown() EndIf getFolder("E:");Enter Your location here Func getFolder($root) If FileExists($root) = 1 Then $Folder = _FileListToArray($root, "*", 2) $File = _FileListToArray($root, "*", 1) $F1 = _ArraySearch($Folder, "RECYCLER") $F2 = _ArraySearch($Folder, "System Volume Information") If $F1 > 0 Then _ArrayDelete($Folder, $F1) ElseIf $F2 > 0 Then _ArrayDelete($Folder, $F2) EndIf _SQLite_Startup() _SQLite_Open($Database) For $1 = 1 To $File[0] _SQLite_Exec(-1, 'INSERT into dir values ("' & $root & "\" & $File[$1] & '");') Next For $2 = 1 To $Folder[0] _SQLite_Exec(-1, 'INSERT into dir values ("' & $root & "\" & $Folder[$2] & '");') getFolder($root & "\" & $Folder[$2]) Next _SQLite_Close() _SQLite_Shutdown() ElseIf FileExists($root) = 0 Then Exit EndIf EndFunc ;==>getFolder Link to comment Share on other sites More sharing options...
Gigglestick Posted July 30, 2008 Share Posted July 30, 2008 (edited) Some issues:If RECYCLER is found, it skips checking for and deleting System Volume InformationWhy enter the files and folders into the database separately, but in the same table? Why not a single list and loop?_ArrayDelete doesn't update the counter in [0], you must do itMake sure the database connection is successfulUse the handle of the database connection to close it correctlyExiting directly from a function is bad form; return a value and let the calling code decide to exitMaybe something more like this... (I prefer to throw errors first and leave the 'good' code for last... personal preference)Func _GetFolder($sRoot) Local $sFilesAndFolders, $aExemptions, $iExemption Local $hDatabase $aExemptions = StringSplit("RECYCLER;System Volume Information", ";") If Not FileExists($sRoot) Then Return SetError(1, 1, 0); Returns 0 (False), @error=1, @extended=1 (Root not found) Else $sFilesAndFolders= _FileListToArray($sRoot, "*"); Defaults to files AND folders For $i = 1 to $aExemptions[0] $iExemption = _ArraySearch($sFilesAndFolders, $aExemptions[$i]) If $iExemption > 0 Then _ArrayDelete($sFilesAndFolders, $iExemption) $sFilesAndFolders[0] -= 1 EndIf Next _SQLite_Startup() $hDatabase = _SQLite_Open($Database) If $hDatabase = 0 Then Return SetError(1, 2, 0); Returns 0 (False), @error=1, @extended=2 for database connection issue Else For $i = 1 To $sFilesAndFolders[0] _SQLite_Exec(-1, 'INSERT into dir values ("' & $sRoot & "\" & $sFilesAndFolders[$i] & '");') Next _SQLite_Close($hDatabase) _SQLite_Shutdown() Return SetError(0, 0, 1); Returns 1 (True) EndIf EndIf EndFunc ;==>_GetFolderThe $aExemptions allows you to expand your exemptions without modifying the code. Edited July 30, 2008 by c0deWorm My UDFs: ExitCodes Link to comment Share on other sites More sharing options...
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