Jump to content
Sign in to follow this  

File/Folder List

Recommended Posts


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

#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 
    _SQLite_Exec(-1, "Create table IF NOT EXISTS dir (dir BLOB);")

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)
        For $1 = 1 To $File[0]
            _SQLite_Exec(-1, 'INSERT into dir values ("' & $root & "\" & $File[$1] & '");')
        For $2 = 1 To $Folder[0]
            _SQLite_Exec(-1, 'INSERT into dir values ("' & $root & "\" & $Folder[$2] & '");')
            getFolder($root & "\" & $Folder[$2])
    ElseIf FileExists($root) = 0 Then
EndFunc  ;==>getFolder

Share this post

Link to post
Share on other sites

Some issues:

  • If RECYCLER is found, it skips checking for and deleting System Volume Information
  • Why 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 it
  • Make sure the database connection is successful
  • Use the handle of the database connection to close it correctly
  • Exiting directly from a function is bad form; return a value and let the calling code decide to exit
Maybe 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)
        $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
        $hDatabase = _SQLite_Open($Database)
        If $hDatabase = 0 Then
            Return SetError(1, 2, 0); Returns 0 (False), @error=1, @extended=2 for database connection issue
            For $i = 1 To $sFilesAndFolders[0]
                _SQLite_Exec(-1, 'INSERT into dir values ("' & $sRoot & "\" & $sFilesAndFolders[$i] & '");')
            Return SetError(0, 0, 1); Returns 1 (True)
EndFunc ;==>_GetFolder

The $aExemptions allows you to expand your exemptions without modifying the code.

Edited by c0deWorm

My UDFs: ExitCodes

Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.