NoMercy Posted May 17, 2009 Share Posted May 17, 2009 (edited) Hello guys... im trying to find(i need source code)/make a program that searches for a specific file on the hard disk without specifying the path.... for example to search for a .doc file on all the hard disk. can any1 point me in the right direction please? i`ve spent 2days searching but didnt find anything on the net. -tnx Edited May 17, 2009 by NoMercy Link to comment Share on other sites More sharing options...
Dampe Posted May 17, 2009 Share Posted May 17, 2009 Look up _FileListToArray() _ArraySearch() Easily done. Link to comment Share on other sites More sharing options...
NoMercy Posted May 17, 2009 Author Share Posted May 17, 2009 (edited) ill try.. tnx.. if anyone else has anymore suggestions id be glad to hear them Edited May 17, 2009 by NoMercy Link to comment Share on other sites More sharing options...
Authenticity Posted May 17, 2009 Share Posted May 17, 2009 Search the keyword "Recursive" in the Example Scripts forum, you'll come up with a lot of examples and code. Link to comment Share on other sites More sharing options...
NoMercy Posted May 17, 2009 Author Share Posted May 17, 2009 i think im onto something now... tnx Authenticity... Link to comment Share on other sites More sharing options...
NoMercy Posted May 17, 2009 Author Share Posted May 17, 2009 (edited) still cant find what i need...i need a program that for example searches for all .doc and writes them into a file... Edited May 17, 2009 by NoMercy Link to comment Share on other sites More sharing options...
Inverted Posted May 17, 2009 Share Posted May 17, 2009 (edited) Make the functions mentioned to create an filelist array from a folder, then go through it to isolate all the .doc files. Edited May 17, 2009 by Inverted Link to comment Share on other sites More sharing options...
KaFu Posted May 17, 2009 Share Posted May 17, 2009 (edited) Give my program "SMF" a try ... Edited May 17, 2009 by KaFu  OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
NoMercy Posted May 17, 2009 Author Share Posted May 17, 2009 Give my program "SMF" a try ...my god its tooo complicated lol... i just need a simple script... Link to comment Share on other sites More sharing options...
NoMercy Posted May 17, 2009 Author Share Posted May 17, 2009 Make the functions mentioned to create an filelist array from a folder, then go through it to isolate all the .doc files.how can i do that? pls help im not that good with autoit... im still learning... if you have some time pls show me how. Link to comment Share on other sites More sharing options...
NoMercy Posted May 17, 2009 Author Share Posted May 17, 2009 any ideas guys? i rly need this to work... pls Link to comment Share on other sites More sharing options...
MrMitchell Posted May 17, 2009 Share Posted May 17, 2009 I did a forum search for "recursive" ... came up with this on the first page: http://www.autoitscript.com/forum/index.ph...mp;hl=recursiveI found at least 2 working examples out of several on this page. It seems they search everything first then give you results. So be patient when doing the search. Link to comment Share on other sites More sharing options...
NoMercy Posted May 17, 2009 Author Share Posted May 17, 2009 ye i saw them and used the same concept but i still cant find what i need ... Link to comment Share on other sites More sharing options...
MrMitchell Posted May 17, 2009 Share Posted May 17, 2009 This one worked for me: #include <File.au3> #include <Array.au3> Global $sRet Local $sPath = @WindowsDir Local $sFindFile = "calc.exe" $aRetArray = _FindPathName($sPath, $sFindFile) _ArrayDisplay($aRetArray) ; Searches all subfolders of $sPath for $sFindFile (* and ? wildcards accepted) ; Returns an array containing full path and name of all matches. ; Number of matches is in zero index of array Func _FindPathName($sPath, $sFindFile) Local $sSubFolderPath, $iIndex, $aFolders $search = FileFindFirstFile($sPath & "\" & $sFindFile) $aFolders = _FileListToArray($sPath, "*", 2) While 1 $file = FileFindNextFile($search) If @error Then ExitLoop Else $sRet &= $sPath & "\" & $file & "|" EndIf WEnd FileClose($search) For $iIndex = 1 To $aFolders[0] $sSubFolderPath = $sPath & "\" & $aFolders[$iIndex] $aFoldersSubs = _FileListToArray($sSubFolderPath, "*", 2) If IsArray($aFoldersSubs) Then _FindPathName($sSubFolderPath, $sFindFile) Next Return StringSplit(StringTrimRight($sRet,1), "|") EndFunc ;==>_FindPathName What isn't working for you? Link to comment Share on other sites More sharing options...
MrMitchell Posted May 17, 2009 Share Posted May 17, 2009 Here's another, though a very weird, way to do it: expandcollapse popup#include <constants.au3> #include <Array.au3> Dim $fileList[1] $fileList[0] = "" $searchString = InputBox("Enter search", "What files do you want to find?", "*.doc") $cmd = 'dir \' & $searchString & ' /s | find /I "directory of"' $result = _CMDreturn($cmd) If Not $result Or StringInStr($result, "File Not Found") Then MsgBox(0, "", "No Files Found!") Exit EndIf $directories = StringRegExp($result, '[a-zA-Z]:\\[^/:*?"<>|]*[\r\n]', 3) For $i = 0 To UBound($directories) - 1 $dir = StringTrimRight($directories[$i],2) ;ConsoleWrite("$dir = " & $dir & @CRLF) If Not FileChangeDir($dir) Then ConsoleWrite("Unable to change directory to: " & $dir & @CRLF) ExitLoop EndIf $search = FileFindFirstFile($searchString) ;ConsoleWrite("$search = " & $search & ", and @error = " & @error & @CRLF) If $search = -1 Then ExitLoop While 1 $file = FileFindNextFile($search) If @error Then ExitLoop ;ConsoleWrite("$file = " & $file & @CRLF) _ArrayAdd($fileList, $dir & "\" & $file) WEnd FileClose($search) Next $fileList[0] = UBound($fileList) - 1 _ArrayDisplay($fileList) Exit Func _CMDreturn($sCommand) ; This function returns the output of a DOS command as a string Local $cmdreturn = "" Local $line, $stream $stream = Run(@ComSpec & " /c " & $sCommand, @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD) While 1 ; loop through the return from the command until there is no more $line = StdoutRead($stream) If @error Then ExitLoop $cmdreturn &= $line WEnd Return $cmdreturn EndFunc ;==>_CMDreturn It's buggy but works for your purpose, probably won't work 100% of the time either...but since we're on the subject and nothing else is working for you I figure why not post it? Link to comment Share on other sites More sharing options...
Valuater Posted May 17, 2009 Share Posted May 17, 2009 I think this is the BEST one in Autoithttp://www.autoitscript.com/forum/index.ph...st&p=1413358) Link to comment Share on other sites More sharing options...
NoMercy Posted May 18, 2009 Author Share Posted May 18, 2009 (edited) ok im using this and its working : but how can i copy all these .doc files to another destination or delete them (im using the FileMove() and the FileDelete() ) not sure what im doing wrong... and tnx for the help ppl... expandcollapse popup#include <File.au3> #include <Array.au3> Global $sRet Local $sPath = "e:\" Local $sFindFile = "*.doc" $aRetArray = _FindPathName($sPath, $sFindFile) _ArrayDisplay($aRetArray) ; Searches all subfolders of $sPath for $sFindFile (* and ? wildcards accepted) ; Returns an array containing full path and name of all matches. ; Number of matches is in zero index of array Func _FindPathName($sPath, $sFindFile) Local $sSubFolderPath, $iIndex, $aFolders $search = FileFindFirstFile($sPath & "\" & $sFindFile) $aFolders = _FileListToArray($sPath, "*", 2) While 1 $file = FileFindNextFile($search) If @error Then ExitLoop Else $sRet &= $sPath & "\" & $file & "|" FileMove($sRet,"c:\") ;move files FileDelete($sRet) ; Delete files EndIf WEnd FileClose($search) For $iIndex = 1 To $aFolders[0] $sSubFolderPath = $sPath & "\" & $aFolders[$iIndex] $aFoldersSubs = _FileListToArray($sSubFolderPath, "*", 2) If IsArray($aFoldersSubs) Then _FindPathName($sSubFolderPath, $sFindFile) Next Return StringSplit(StringTrimRight($sRet,1), "|") EndFunc;==>_FindPathName Edited May 18, 2009 by NoMercy Link to comment Share on other sites More sharing options...
NoMercy Posted May 19, 2009 Author Share Posted May 19, 2009 any ideas guys? Link to comment Share on other sites More sharing options...
Authenticity Posted May 19, 2009 Share Posted May 19, 2009 $sRet contains string which is not a valid file name and thus doesn't exist. The pipe for example is not a valid file name character. Use MsgBox() or ConsoleWrite() to see what $sRet contains and then you'll understand. Link to comment Share on other sites More sharing options...
NoMercy Posted May 19, 2009 Author Share Posted May 19, 2009 ok i managed to get it working... tnx for everything guys,,, and sorry for bothering you so much Link to comment Share on other sites More sharing options...
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