TXTechie Posted August 1, 2013 Posted August 1, 2013 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?
Edano Posted August 1, 2013 Posted August 1, 2013 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]
BrewManNH Posted August 1, 2013 Posted August 1, 2013 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 GudeHow 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 Melba23 Posted August 1, 2013 Moderators Posted August 1, 2013 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
TXTechie Posted August 1, 2013 Author Posted August 1, 2013 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 Melba23 Posted August 1, 2013 Moderators Posted August 1, 2013 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Edano Posted August 1, 2013 Posted August 1, 2013 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]
TXTechie Posted August 1, 2013 Author Posted August 1, 2013 Melba23 & Edano, Thank you very much for the information, I will start playing around with _RecFileListToArray UDF. Thanks!
TXTechie Posted August 1, 2013 Author Posted August 1, 2013 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?
BrewManNH Posted August 1, 2013 Posted August 1, 2013 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 GudeHow 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 Melba23 Posted August 1, 2013 Moderators Posted August 1, 2013 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
TXTechie Posted August 1, 2013 Author Posted August 1, 2013 (edited) Thanks for the clarification, BrewManNH & Melba23! And, yes, I did just notice that I had left the C: drive hard-coded. I have been modifying it. Edited August 1, 2013 by TXTechie
TXTechie Posted August 1, 2013 Author Posted August 1, 2013 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?
BrewManNH Posted August 1, 2013 Posted August 1, 2013 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 GudeHow 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 Melba23 Posted August 1, 2013 Moderators Posted August 1, 2013 (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. M23Edit:#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 August 1, 2013 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Wombat Posted August 1, 2013 Posted August 1, 2013 (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 August 1, 2013 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...
TXTechie Posted August 1, 2013 Author Posted August 1, 2013 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!
TXTechie Posted August 1, 2013 Author Posted August 1, 2013 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 Melba23 Posted August 1, 2013 Moderators Posted August 1, 2013 Wombat, her wrappersI have a perfectly good Y chromosome I would have you know! M23 Wombat 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Wombat Posted August 1, 2013 Posted August 1, 2013 (edited) Wombat, I have a perfectly good Y chromosome I would have you know! 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 August 1, 2013 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...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now