Jump to content

Find Directories using wildcards


Recommended Posts

I'm trying to find directories based off wildcard matches. I've having a lot of difficulties doing it so I thought I'd post this and see if anyone had any ideas.

;=====================================
; OPTIONS
;=====================================
Opt("TrayIconDebug", 0)
Opt("WinTitleMatchMode", 2)
Opt("WinDetectHiddenText",1)
Opt("TrayIconHide", 1)

; ========================
; INCLUDE HELPER FUNCTIONS
; ========================
#include <constants.au3>
#include <String.au3>
#include <Array.au3>
#include <file.au3>
#include <process.au3>

;=============================
; VARIABLES AND DECLARATIONS
;=============================
Dim $MATCHING [1][1]
Dim $search
Dim $FILE
Dim $INILOC

;================
; MAIN
;================
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Install Needed Files
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DirCreate(@SystemDir & "\SCAN")

$INILOC = @ScriptDir & "\SCAN.ini"

FileCopy($INILOC, @SystemDir & "\SCAN\SCAN.ini", 1)

$INILOC = @SystemDir & "\SCAN\SCAN.ini"

$handle=FileOpen(@SystemDir & "\scan\scan2.txt", 1)

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Read .ini File
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
$MATCH = IniRead($INILOC, "MATCHING", "MATCH", "0")

If $MATCH = "1" Then
    $MATCHING = IniReadSection($INILOC, "MATCHING")
EndIf

;_ArrayDisplay($MATCHING, "Folders")

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Find Match
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
For $a = 1 To $MATCHING[0][0]
    
    $search = FileFindFirstFile($MATCHING[$a][1])  
    
    If $search <> -1 Then
        While 1
            $FILE = FileFindNextFile($search)
            
            If @error Then ExitLoop
            
            If $FILE <> "" Then
                
                MsgBox(0, "TEST", $FILE)
                
                ; Write to new file
                $Result=_FileWriteToLine(@SystemDir & "\SCAN\scan2.txt", 1, "FoundFolder=" & $MATCHING[$a][1] & $FILE, 0)
                
            EndIf
        WEnd
    EndIf
    
    ; Close the search handle
    FileClose($search)
    
Next

FileClose($handle)

It is all working down to the search part which maybe there's a better way?

The ini file would look something like this:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

[MATCHING]

; Description - WILCARD

MATCH=1

Folder=C:\Documents and Settings\All Users\Application Data\Adobe\Acrobat\*.0\Replicate

Folder=C:\Documents and Settings\All Users\Application Data\Adobe\Reader\*

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Any suggestions would be great, thanks.

Terry

Link to comment
Share on other sites

Lot of extra code in there...

it looks like you've got the FFFF/FFNF handle / query syntax correct.

Are you getting the filenames you expect?

I created a helper function _IsDir() , which just does this:

Func _IsDir($dir='')
;Returns 1 if Directory exists, 0 otherwise.
If StringRight($dir,1) == "\" then $dir = StringTrimRight($dir,1)
 If Not FileExists($dir) Then Return 0
 If StringInStr(FileGetAttrib($dir), "D") = 0 Then Return 0
 Return 1
EndFunc

To aid in debugging, you may wish to declare a variable like $current_file to be the result of your FFNF() function. Ensure you're getting the results you expect there, then test whether the search match is a directory.

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Link to comment
Share on other sites

Lot of extra code in there...

it looks like you've got the FFFF/FFNF handle / query syntax correct.

Are you getting the filenames you expect?

I created a helper function _IsDir() , which just does this:

Func _IsDir($dir='')
;Returns 1 if Directory exists, 0 otherwise.
If StringRight($dir,1) == "\" then $dir = StringTrimRight($dir,1)
 If Not FileExists($dir) Then Return 0
 If StringInStr(FileGetAttrib($dir), "D") = 0 Then Return 0
 Return 1
EndFunc

To aid in debugging, you may wish to declare a variable like $current_file to be the result of your FFNF() function. Ensure you're getting the results you expect there, then test whether the search match is a directory.

Thanks, I'm definately not the best at this, I usually just limp by :D

How does yours take into account the wildcard?

Link to comment
Share on other sites

The wildcard is utilized in the FFFF() function. This gives you the handle that FFNF() uses for giving you a list of matching file names.

$files_matching = "*.*"  ;or any other valid wildcard expression
$search_handle = FileFindFirstFile($files_matching)

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

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...