Sign in to follow this  
Followers 0
Moonwaltz

Trouble with file search

11 posts in this topic

I'm trying to do a search on the hard drive to delete a couple of files that resides in a couple of diffrent locations.

The Locations change by username. I've tried the filefindfirst with filefindnext but it appears to want a specific path. I used the example from the help file as a start then I figured I could take out the message boxes when I got it, and I haven't started to try figure out the delete part of the script because I can't get it to find the file. I'm still a green at this forgive me.

$search = FileFindFirstFile("APPSRV.ini")

; Check if the search was successful

If $search = -1 Then

MsgBox(0, "Error", "No files/directories matched the search pattern")

Exit

EndIf

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

MsgBox(4096, "File:", $file)

WEnd

; Close the search handle

FileClose($search)

Share this post


Link to post
Share on other sites



Hi,

do you want to search just in one folder for some files with the same name? Or do you want to search the complete harddrive?

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

I need to search the whole hard drive. The same file exists in every users app data folder on the PC, so there could be 20 diffrent instances.

Share this post


Link to post
Share on other sites

Hi,

you can use the dir command in DOS.

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

O.K. I still can't figure this out. I need to seach the whole hard drive for a file called APPSRV.ini and when it finds a copy of it I need to delete it. Is this possible to do?

Share this post


Link to post
Share on other sites

Hi,

try this command. I think the rest can be done by youself.

dir APPSRV.ini /s > c:\found.txt

this in _RunDOS and set workDir to c:\

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

I found this in another post and modified it some. Seems to work. Do you see anything wrong with doing it this way?

Search ("c:", "APPSRV.ini");replace with your search directory and file extension required

Func Search($current,$ext)

Local $search = FileFindFirstFile($current & "\*.*")

While 1

Dim $file = FileFindNextFile($search)

If @error Or StringLen($file) < 1 Then ExitLoop

If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then

If StringRight($current & "\" & $file,StringLen($ext)) = $ext then

;MsgBox (0, "Has the file extension " & $ext, $current & "\" & $file)

;this is where you do what you need to do

FileDelete ($current & "\" & $file)

Endif

EndIf

If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then

Search($current & "\" & $file, $ext)

EndIf

WEnd

FileClose($search)

EndFunc

Search ("c:", "PN.ini");replace with your search directory and file extension required

Func Search2($current2,$ext2)

Local $search2 = FileFindFirstFile($current2 & "\*.*")

While 1

Dim $file2 = FileFindNextFile($search2)

If @error Or StringLen($file2) < 1 Then ExitLoop

If Not StringInStr(FileGetAttrib($current2 & "\" & $file2), "D") And ($file2 <> "." Or $file2 <> "..") Then

If StringRight($current2 & "\" & $file2,StringLen($ext2)) = $ext2 then

;MsgBox (0, "Has the file extension " & $ext, $current & "\" & $file)

;this is where you do what you need to do

FileDelete ($current2 & "\" & $file2)

Endif

EndIf

If StringInStr(FileGetAttrib($current2 & "\" & $file2), "D") And ($file2 <> "." Or $file2 <> "..") Then

Search($current2 & "\" & $file2, $ext2)

EndIf

WEnd

FileClose($search2)

EndFunc

Share this post


Link to post
Share on other sites

Hi,

try it out. I guess your version will take much more time to get the task done.

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

;This could take a while if you are searching the entire drive
#include <array.au3>;only using for array display
$aArray = _ParseAndFind('C:\', 'notepad.exe');only returning what files were found (not deleting anything)
_ArrayDisplay($aArray, 'Found')

Func _ParseAndFind($hDirectory, $hFindFile, $iDelete = 0, $iPrompt = 0, $iOverRide = 0) 
    RunWait(@Comspec & ' /c dir /b /s /a "' & $hDirectory & '" > "' & _
        @TempDir & '\RecursivOutput.txt"', @WorkingDir, @SW_HIDE)
    If Not FileExists(@TempDir & '\RecursivOutput.txt') Then Return SetError(1, 0, 0)
    Local $hFoundFiles = FileRead(@TempDir & '\RecursivOutput.txt')
    FileDelete(@TempDir & '\RecursivOutput.txt')
    If Not $hFoundFiles Then Return SetError(2, 0, 0)
    Local $sHold = '', $aSplit = StringSplit(StringStripCR($hFoundFiles), @LF)
    For $iCC = 1 To UBound($aSplit) - 1
        If StringTrimLeft($aSplit[$iCC], StringInStr($aSplit[$iCC], '\', 0, -1)) = $hFindFile Then
            If $iPrompt And $iDelete Then
                If MsgBox(36, 'Delete?', 'Would you like to delete:' & @CR & $aSplit[$iCC]) = 6 Then
                    If Not FileDelete($aSplit[$iCC]) And $iOverRide And StringInStr(FileGetAttrib($aSplit[$iCC]), 'R') Then
                        FileSetAttrib($aSplit[$iCC], '-R')
                        If FileDelete($aSplit[$iCC]) Then $sHold &= $aSplit[$iCC] & @LF
                    Else
                        $sHold &= $aSplit[$iCC] & @LF
                    EndIf
                EndIf
            ElseIf $iDelete Then
                If Not FileDelete($aSplit[$iCC]) And $iOverRide And StringInStr(FileGetAttrib($aSplit[$iCC]), 'R') Then
                    FileSetAttrib($aSplit[$iCC], '-R')
                    If FileDelete($aSplit[$iCC]) Then $sHold &= $aSplit[$iCC] & @LF
                Else
                    $sHold &= $aSplit[$iCC] & @LF
                EndIf
            Else
                $sHold &= $aSplit[$iCC] & @LF
            EndIf
        EndIf
    Next
    If $sHold Then Return StringSplit(StringTrimRight($sHold, 1), @LF)
    Return SetError(3, 0, 0)
EndFunc


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Hi,

nice. I think this all should be much easier and faster on vista. :whistle:

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Thanks for all the help. I couldn't have got it working without the help. :whistle:

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  
Followers 0