Jump to content
Sign in to follow this  
TXTechie

Looking for fast/efficient way to search PC for certain files

Recommended Posts

TXTechie

Hello Everyone,

I'm looking for what you think would be a fast and efficient way to search an entire PC (at least all fixed drives, possibly attached USB drives?) for all .ftp & .bat files (in my case).

Then, I'll need to read the contents of each of these files doing a find & replace function on each file.

Can someone recommend the best way to start this project?

Share this post


Link to post
Share on other sites
Edano

FileFindFirstFile ( "filename" )

you'll find thousands of examples in the forum

E.


[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites
BrewManNH

You're going to need to use a recursive/iterative file search function, or build your own, to search for all files of a certain type. 


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Melba23

TXTechie,

You can use the _RecFileListToArray UDF in my sig to get an array of these files - or the _FileListToArrayRec function in the latest Beta which is essentially the same code. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
TXTechie

Well, I'm wondering which of the following (or something else that I haven't found yet) might be faster and/or more efficient for this purpose?:

  • FileFindFirstFile & FileFindNextFile
  • _FileListToArray()
  • RecFileListToArray
  • other?

Share this post


Link to post
Share on other sites
Melba23

TXTechie,

The latter 2 are wrappers for FileFindFirst/NextFile to save you having to code it all yourself. :)

_FileListToArray lists in a single folder - _RecFileListToArray (or as I explained above _FileListToArrayRec in the Beta) lists recursively into all subfolders (and a whole lot more). ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Edano

they are all based on FileFindFirstFile & FileFindNextFile afaik. searching the entire computer will take a lot of time for sure


[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites
TXTechie

Melba23 & Edano,

Thank you very much for the information, I will start playing around with _RecFileListToArray UDF.

Thanks!

Share this post


Link to post
Share on other sites
TXTechie

I'm using the following script:

#include <Array.au3>
#include "RecFileListToArray.au3" ; External UDF by Melba

#NoTrayIcon

Local  $aFileList, $aDrives = DriveGetDrive("FIXED")
If @error Then
    ; An error occurred when retrieving the drives.
    MsgBox(4096, "Drives", "It appears an error occurred.")
Else
    For $i = 1 To $aDrives[0]
        ; Show all the drives found and convert the drive letter to uppercase.
        MsgBox(4096, "DriveGetDrive", "Drive " & $i & "/" & $aDrives[0] & " = " & StringUpper($aDrives[$i]))
        ; Search the drive for all .bat & .ftp files
        $aFileList = _RecFileListToArray("C:\", "*.bat;*.ftp", 0, 1, 0, 2)
    Next
EndIf

_ArrayDisplay($aFileList, @ScriptName)

The _ArrayDisplay function only displays the folder path, not the actual filename - how can I get the full path to the .bat or .ftp file, since I'll need it later in order to perform the find & replace on them?

Share this post


Link to post
Share on other sites
BrewManNH

Change the $iReturn parameter to 1 and try it again.

BTW, the way you have it written won't work the way you want it to. The search will always be done on the C: drive and even if written correctly, the array returned is always going to only contain the last drive checked.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Melba23

TXTechie,

You are asking the UDF to return "Folders and Files" ($iReturn = 0) so it is not surprising that you get a lot of folders in the returned array - you need to set that parameter to 1 ("Files only"). When I do that and run the calling line I get only files with a full path displayed. :)

But you do realise that at the moment you are only searching the C: drive? You need to use $aDrives[$i] in the $sPath parameter - and concatenate the returned arrays - to search the whole machine. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
TXTechie

Thanks for the clarification, BrewManNH & Melba23! And, yes, I did just notice that I had left the C: drive hard-coded. :oops:

I have been modifying it.

Edited by TXTechie

Share this post


Link to post
Share on other sites
TXTechie

Ok, I'm sorry but I've not worked a lot with arrays, how would I go about concatenating the array in a loop like this?

Share this post


Link to post
Share on other sites
BrewManNH

Do something like this, where it says do something here, you could call a function to do the find and replace on the files found, passing the array as an argument to the function.

#include <Array.au3>
#include "RecFileListToArray.au3" ; External UDF by Melba

#NoTrayIcon

Local $aFileList, $aDrives = DriveGetDrive("FIXED")
If @error Then
    ; An error occurred when retrieving the drives.
    MsgBox(4096, "Drives", "It appears an error occurred.")
Else
    For $i = 1 To $aDrives[0]
        ; Show all the drives found and convert the drive letter to uppercase.
        MsgBox(4096, "DriveGetDrive", "Drive " & $i & "/" & $aDrives[0] & " = " & StringUpper($aDrives[$i]))
        ; Search the drive for all .bat & .ftp files
        $aFileList = _RecFileListToArray($aDrives[$i], "*.bat;*.ftp", 0, 1, 0, 2)
        ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Do what you need to do with the array here, not after the loop has ended.
        _ArrayDisplay($aFileList, @ScriptName)
    Next
EndIf

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Melba23

TXTechie,

_ArrayConcatenate is what you need. But remember that you need to skip the [0] count element when concatenating - and add the value therein to the [0] element of the resulting array so you keep the correct count. ;)

Give me a moment and I will produce a quick example. :)

M23

Edit:

#include <Array.au3>

; Here are our 2 arrays
Global $aArray_1[5] = [4, 1, 2, 3, 4]
Global $aArray_2[3] = [2, "A", "B"]

; Add the count of the second to the first
$aArray_1[0] += $aArray_2[0]

; And now concatenate the arrays - missing the count element of the second
_ArrayConcatenate($aArray_1, $aArray_2, 1)

; and here is the result
_ArrayDisplay($aArray_1)
Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Wombat

Darn,

I was hoping I could jump in here and help out but the pros beat me to it lol. I highly recommend _RecFileListToArray it has just about everything you'll need to run a search function. Bit of advice= read the UDF then reread it until you know it front and back, its all there. Melba23 does a great job of explaining how to use her his wrappers in the udf.

Edited by Wombat

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Share this post


Link to post
Share on other sites
TXTechie

BrewManNH - Thanks, that makes sense - just do what I need to it before checking another drive, no need to concatenate.

Melba23 - Thank you for the example... I would have NEVER come up with how to do that on my own (I did see and study the _ArrayConcatenate function, but I still couldn't figure out how to go about coding it).

Again, thank you both!  :rolleyes:

Share this post


Link to post
Share on other sites
TXTechie

Hi Wombat,

Thank you for the additional advice and information. I'll have to read the UDF more closely for clues on how to use it! Thanks (to you and Melba23)!

Share this post


Link to post
Share on other sites
Melba23

Wombat,

 

her wrappers

I have a perfectly good Y chromosome I would have you know! :D

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Wombat

Wombat,

 

I have a perfectly good Y chromosome I would have you know! :D

M23

 

I knew you're male, I have no idea why i typed her and not his, lets chalk it up to a errored keystroke.... My apologies

Edited by Wombat

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

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  

  • Similar Content

    • Trisha
      By Trisha
      Hello,
      I Have clicked on save as option to save a file, while doing that I need to rename a file appending with sysdate. I have searched in google find the below one line of code:
      FileMove("C:\somefile.txt", "C:\somefile1.txt"), When I am trying to append with sysdate. It is not happening. Please help me out  with the small issue.
    • lenclstr746
      By lenclstr746
      HELLO GUYS
      I'm a work on a background see and click bot project 
      I can complete it if your help me
      (using imagesearch , gdi+ and  fastfind)
    • dadalt95
      By dadalt95
      Perform a simple google search!
      The script below works fine until fill the google form!
      What I can't find is how to submit the form, tried a couple of ways and none of them worked.

       
      #include <IE.au3> $oIE = _IECreate ("www.google.com") $o_form = _IEFormGetObjByName ($oIE, "f") $o_login = _IEFormElementGetObjByName ($o_form, "q") $username = "80251369" _IEFormElementSetValue ($o_login, $username) $o_numer = _IEGetObjByName($o_form, "btnK") _IEAction ($o_numer, "click")  
      The code runs without any problem.
      I don't know how to proceed!
      Thanks in advance!
    • nacerbaaziz
      By nacerbaaziz
      Hi dears
      how are you? I hope You fine
      I have a question please
      I've created a listView
      It has several columns
      Is there any way  to search for text in an element of this list with text in all columns
      for example
      list view with 2 column
      the first is the file name and the second is the file path
      and i want to search for the item witch Containt the name and the path toGether
      I searched a lot but could not find what I was looking for
      If you do not understand the idea that I'm looking for, I can put an example
      Thanks in advance
    • lewisg
      By lewisg
      Suddenly a RunWait command has stop working after 2 years of no errors, issues, or problems. The code uses RunWait to start Plink.exe, a command-line remote connection tool similar to UNIX ssh. I'm using it to ssh to a linux (Centos) machine, run a Perl script, and redirect the output to a file on a PC running the AutoIt script.  
       
      $FilePath = "C:\AutoIT\LED" $FilePathPlus = $FilePath & "\plink.exe" $Code1 = RunWait(@ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt ", @SW_SHOW) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " = ' & @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console The ConsoleWrite output when cut-n-pasted into a DOS box produces the expected file so I know it works. I've also tried many variations of the function moving, adding, and changing the " and ' (quote) marks. Also tried it without the @ComSpec macro and other related functions...e.g.  ShellExecuteWait , etc.
      The PC is a Windows 10 64bit and AutoIT is version 3.3.14.2.
      Searching here and Google has not yielded any clues that helped. 
×