Jump to content

Recommended Posts

Posted

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?

Posted

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]

Posted

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

  • Moderators
Posted

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

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

 

Posted

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?
  • Moderators
Posted

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

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

 

Posted

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]

Posted

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?

Posted

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

  • Moderators
Posted

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

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

 

Posted (edited)

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
Posted

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

  • Moderators
Posted (edited)

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

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

 

Posted (edited)

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

Posted

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:

Posted

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)!

  • Moderators
Posted

Wombat,

 

her wrappers

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

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

 

Posted (edited)

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

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
×
×
  • Create New...