Jump to content

scanning for files/folders help please


am632
 Share

Recommended Posts

Hi,

Im trying to make a simple adware/junk remover. I plan to store a list of files, folders, registry keys etc in a simple database which I have made using Sqlitebrowser.

I have put together this script so far,which loads the db and displays a list of the results in 3 arays (1 for each table)

#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <File.au3>

Local $aResultFolders, $aResultFiles, $iRows, $iColumns, $Database, $DBTABLEFOLDERS, $DBTABLEFILES, $DBTABLEREGISTRY, $aResultRegistry

SplashTextOn("","Loading Database",100,60,-1,-1)
_SQLite_Startup()
If @error Then
    MsgBox($MB_SYSTEMMODAL, "SQLite Error", "SQLite.dll Can't be Loaded!")
    Exit -1
EndIf

$Database = _SQLite_Open(@ScriptDir & "\database.db")
If @error Then
    MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't Load Database!")
    Exit -1
EndIf
SplashOff()

$DBTABLEFOLDERS = _SQLite_GetTable($Database,"SELECT * FROM folders;", $aResultFolders,$iRows,$iColumns)
$DBTABLEFILES = _SQLite_GetTable($Database,"SELECT * FROM files;", $aResultFiles, $iRows, $iColumns)
$DBTABLEREGISTRY = _SQLite_GetTable($Database,"SELECT * FROM registry;", $aResultRegistry, $iRows, $iColumns)

    _ArrayDisplay($aResultFolders, "Query Result")
    _ArrayDisplay($aResultFiles, "Query Result")
    _ArrayDisplay($aResultRegistry, "Query Result")

Func _SearchFiles()

EndFunc

_SQLite_Close()
_SQLite_Shutdown()

Im struggling with the next part which is a function to search the computer for the content in the database to see if it exists. (I will list the found items in a listview later but just displaying them in an array will do for now)

Would I use the FindFileFirstFile & FindFileNextFile functions for this? I have looked in the help file and im not sure how i'd use the info from my array returned from the database with this. Also would these functions search for folders aswell? I have looked in the helpfile for searching the registry aswell but I dont know which function i'd use for this is there 1 builtin or would I need a 3rd party function? If I wanted to do a general search of the registry for a keyword for example, the sample 'junk' i used in my database is some software called 'pcfixspeed' so I'd want to search the registry for all references to this.

I have attached my database file which i'm using with this script.

Thanks

database.zip

Link to comment
Share on other sites

  • Moderators

am632,

To search for files and folders on your drives, I suggest _FileListToArrayRec - this will search all folders recursively, but be warned that it can take a while on large drives. However, you can search for several patterns at a time to help keep the execution time to a minimum. :)

As to the registry, I have never seen a search tool in AutoIt - but that does not mean one does not exist. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

what about FileExists (works for both files and folders) and RegRead ?

Also _IsRegistryExist, or this one :

Func _RegExists($sKeyname, $sValueName = "")
        Local $iRet
        RegRead($sKeyName, $sValueName)
        Return ( $svalueName = "" ? @error <= 0 : @error = 0 )
    EndFunc
Link to comment
Share on other sites

  • Moderators

jguinch,

FileExists requires a full path - not a lot of use if you only know the name. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Feel free to play along here as well:  '?do=embed' frameborder='0' data-embedContent>>

Seems the intent is similar.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Hi, thanks for all the replies, sorry for the late reply I havn't been well recently.

I think the _FileListToArrayRec looks like a good solution for the files search - Could you possibly provide me with an example of how I'd use the information from my $aResultFiles array? I guess the $sMask part of the function would need to be populated with my values from the array right? but I dont know how i'd do this, I cant seem to find an example in the help file. Or is this not the correct way to use this function?

Thanks

Link to comment
Share on other sites

  • 1 month later...

Hi,

Sorry to dig up the old post again but i'm just getting around to continuing my project.

I have a few questions to get the search working, i'm going to forget about the sqdb for the time being while I get the search working correctly, I have the following script to search for all au3's on the c drive and display the results in an array...

#Include <Array.au3>
#include <File.au3>

SplashTextOn("","Scanning for files...","250","100","-1","-1",33,"","","")

$Array = _FileListToArrayRec("C:\","*.au3",1,1,0,1)

SplashOff()

_ArrayDisplay($Array,"Array")

This code works fine, but how can I search for other filetypes such as .bat files at the same time and display in the array? I tried using _FileListToArrayRec("C:","*.au3,*.bat",1,1,0,1) with no success This was just a guess attempt as the help file under the _FileListToArrayRec didn't mension about multiple different includes. My thinking is if I can search for all my file types at once and have them all display in the array it will be quicker than searching for all of 1 file type and displaying the results then searching again for another and so on.

Thanks

Link to comment
Share on other sites

use a semicolon

#include <File.au3>
#include <Array.au3>

$aArray = _FileListToArrayRec(@ScriptDir , "*.exe ; *.au3")

_ArrayDisplay($aArray)

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

  • Moderators

am632,

 

the help file under the _FileListToArrayRec didn't mension about multiple different includes

Oh yes it does! :P

$sMask - [optional] Filter for result. Multiple filters must be separated by ";"

So do as boththose has suggested and it will work. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Ah yes, I see it now :) I must have skipped over it.

This is working as I expect now except it doesnt appear to work for folders, heres what I have so far...

#Include <Array.au3>
#include <File.au3>


SplashTextOn("","Scanning for files...","250","100","-1","-1",33,"","","")

$Array = _FileListToArrayRec("C:\","*au3*",1,1,0,1)

SplashOff()

_ArrayDisplay($Array,"Array")

So the code I have will display all files on my computer with au3 in the name or extension but wont list folders with au3 in the name. I have tried changing the $iReturn parameter to 0 which in the help file says it returns files and folders but all this seems to do for me is list every folder on my pc ignoring the name. Am I using this wrong?

Thanks

Link to comment
Share on other sites

  • Moderators

am632,

 

it doesnt appear to work for folders

Your code:

_FileListToArrayRec("C:\",      "*au3*",  1,        1,       0,      1)
;                    $sFilePath  $sMask    $iReturn  $iRecur  $iSort  $iReturnPath
Now we look at the Help file explanation for $iReturn:

$iReturn [optional] Specifies whether to return files, folders or both and omit those with certain attributes
    $FLTAR_FILESFOLDERS (0) - (Default) Return both files and folders
    $FLTAR_FILES (1) - Return files only
    $FLTAR_FOLDERS (2) - Return Folders only
looking at the value you have set (1) what do you think it will return? :huh:

 

I must have skipped over it.

This seems to be becoming a habit..... :whistle:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...