scythetleppo Posted May 4, 2006 Posted May 4, 2006 Hi, I saw posted code on how to search for any particular file within a specific folder, and more code on how to find within an inputted folder, but Iwas wondering how to find a file you know the name of but not the directory. know whati mean?
CyberSlug Posted May 4, 2006 Posted May 4, 2006 (edited) JdeB has a findfiles.au3 script at the bottom of http://www.autoitscript.com/fileman/users/jdeb/jdeb_autoit_stuff.htmIf you want to search multiple drives, you might need to wrap it in a loop like this (untested):$fileToFind = "something.txt" For $i = Asc("C") To Asc("Z") $drive = Chr($i) & ":" If DriveStatus($drive) = "READY" Then $FILES = _GetFileList($drive, $fileToFind) For $X = 0 To UBound($FILES)-1 MsgBox(0,'found:' & $X, $FILES[$X]) Next EndIf Next Edited May 4, 2006 by CyberSlug Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
scythetleppo Posted May 4, 2006 Author Posted May 4, 2006 JdeB has a findfiles.au3 script at the bottom of http://www.autoitscript.com/fileman/users/jdeb/jdeb_autoit_stuff.htm If you want to search multiple drives, you might need to wrap it in a loop like this (untested):$fileToFind = "something.txt" For $i = Asc("C") To Asc("Z") $drive = Chr($i) & ":" If DriveStatus($drive) = "READY" Then $FILES = _GetFileList($drive, $fileToFind) For $X = 0 To UBound($FILES)-1 MsgBox(0,'found:' & $X, $FILES[$X]) Next EndIf Next ty slug, when I run thescript, it just does nothing but a quick flash. I thoughtmaybe it was because it seemed to be searching in "c:\winutil\autoit3\programs\test" so I triedchanging that to "c:\" and then I get an error. Is this script working but I have to change things or? sorry I'm very new
MadBoy Posted May 4, 2006 Posted May 4, 2006 Here, try this... a bit diffrent aproach .. maybe more savage then JdeB but that's all i could do ;p Program should write the file/files you're searching into log file. Just change those 3 Global variables to fit your needs expandcollapse popup#Include <Array.au3> #include <Constants.au3> #Include <Date.au3> #include <File.au3> Global $log_file = @ScriptDir & "\cd.log" Global $what_to_search = "something.au3" Global $search_where = "F:\" _CDTOTXT($search_where) Func _CDTOTXT($path_to_cdrom) $DirOutput = Run(@ComSpec & " /c DIR /A:D /S " & $path_to_cdrom, '', @SW_HIDE, 2) Local $DirOutputOnce While 1 $DirData = StdoutRead($DirOutput) If @error Then ExitLoop If $DirData Then $DirOutputOnce &= $DirData Else Sleep(10) EndIf WEnd ; Remove spaces from output $DirOutputOnce = StringStripWS($DirOutputOnce, 3) ; Split output into array $DirSplit = StringSplit($DirOutputOnce, @CRLF,1) For $i = 1 To $DirSplit[0] If StringInStr($DirSplit[$i], $path_to_cdrom) Then $DirsLine = StringSplit($DirSplit[$i], ": ",1) If $DirsLine[0] = 2 Then; Testing amount of elements in array, if more then 2 Exits If StringInStr($DirsLine[2], $path_to_cdrom) Then; Making sure that path exists in string $cd_directories = $DirsLine[2] $search_all = FileFindFirstFile($cd_directories & "\" & $what_to_search); Searching for all files in directory If $search_all = -1 Then Else While 1 $search_file = FileFindNextFile($search_all) If @error Then ExitLoop $full_path_to_all = $cd_directories & "\" & $search_file _AddLogToFile($full_path_to_all) WEnd EndIF FileClose($search_all) EndIf EndIf EndIf Next EndFunc Func _AddLogToFile($Text) $file_log = FileOpen($log_file,1) FileWriteLine($file_log, "["& _NowTime(5) & "] - " & $Text & @CRLF) FileClose ( $file_log ) EndFunc My little company: Evotec (PL version: Evotec)
scythetleppo Posted May 4, 2006 Author Posted May 4, 2006 Here, try this... a bit diffrent aproach .. maybe more savage then JdeB but that's all i could do ;p Program should write the file/files you're searching into log file. Just change those 3 Global variables to fit your needsI changed to C:\ and then ran it, Error on line 15 stdoutput ?
MadBoy Posted May 4, 2006 Posted May 4, 2006 I changed to C:\ and then ran it, Error on line 15 stdoutput ? Files\AutoIt3\beta" /UserParams >Running AU3Check (1.54.1.1) params: from:C:\Program Files\AutoIt3\beta +>AU3Check ended.rc:0 >Running:(3.1.1.122):C:\Program Files\AutoIt3\beta\autoit3.exe "C:\dupa.au3" +>AutoIT3.exe ended.rc:0 >Exit code: 0 Time: 8.617 You sure you're using beta.. it works fine here. Output in log file: [04:28:08] - F:\Projects\Project.AU3\Weird.Tests\something.au3 [04:28:08] - F:\Projects\Project.AU3\Weird.Tests2\something.au3 My little company: Evotec (PL version: Evotec)
greenmachine Posted May 4, 2006 Posted May 4, 2006 (edited) Hi, I saw posted code on how to search for any particular file within a specific folder, and more code on how to find within an inputted folder, but Iwas wondering how to find a file you know the name of but not the directory. know whati mean? If you know the file, can I assume you know the extension? If so, this searches C:\ and all subdirectories for that extension, and then finds the file from the output. #include <file.au3> Global $ReadArray[2], $found = 0 ; example file $File = "welcome" $Ext = ".html" RunWait (@ComSpec & " /c dir c:\*" & $Ext & " /s /b > c:\outputfile.txt", "", @SW_HIDE) _FileReadToArray ("c:\outputfile.txt", $ReadArray) For $i = 1 To $ReadArray[0] If StringInStr($ReadArray[$i], $File & $Ext) Then MsgBox (0, "Found File", $ReadArray[$i]) $found = 1 EndIf Next If $found = 0 Then MsgBox (0, "Finished", "No Files Found") FileDelete ("c:\outputfile.txt") Edit - D'oh! Forgot #include. Edited May 4, 2006 by greenmachine
scythetleppo Posted May 4, 2006 Author Posted May 4, 2006 OK, now I'm sad... When I try slugs with non-beta, it gives me error. When I try slugs with beta, it just flashes. When I do a search for cd.log, there's nothing. When I try greens with either, I get error....
Valuater Posted May 4, 2006 Posted May 4, 2006 thats exactly what this does.. search fileshttp://www.autoitscript.com/forum/index.ph...59&hl=Valuater#8)
scythetleppo Posted May 4, 2006 Author Posted May 4, 2006 thats exactly what this does.. search files http://www.autoitscript.com/forum/index.ph...59&hl=Valuater# 8) Very nice script, I don't need any of the GUI though... =[
greenmachine Posted May 4, 2006 Posted May 4, 2006 OK, now I'm sad...When I try slugs with non-beta, it gives me error.When I try slugs with beta, it just flashes. When I do a search for cd.log, there's nothing.When I try greens with either, I get error....What error? I used 3.1.1.118 and got no error.
scythetleppo Posted May 4, 2006 Author Posted May 4, 2006 What error? I used 3.1.1.118 and got no error.Am I running the wrong version? I'm running 3.1.1.122 and I get Error that says Line 8 _FileReadToArray ^Error Unknown Function Name
greenmachine Posted May 4, 2006 Posted May 4, 2006 Heh, right.. I used a test file that already has all the includes. You need #include <file.au3> at the top.
scythetleppo Posted May 4, 2006 Author Posted May 4, 2006 Heh, right.. I used a test file that already has all the includes.You need #include <file.au3> at the top.Yesss it works, found 3 Welcome.htmls..Cool! Thanks!
SandelPerieanu Posted May 4, 2006 Posted May 4, 2006 (edited) FileDelete(@DesktopDir & '\Search.txt') FileWrite(@DesktopDir & '\Search.txt', FileSearch('C:')) Func FileSearch($search_dir, $s_ext = '*.*', $sep_char = @CRLF, $last_line = False) $allfiles = '' $search_dir = StringReplace($search_dir & '\', '\\', '\') $search = FileFindFirstFile($search_dir & '*.*') While 1 $file = FileFindNextFile($search) If $file = '' Then ExitLoop $full_file = $search_dir & $file $check_file = StringInStr(FileGetAttrib($full_file), 'D') If $check_file <> 0 Then $allfiles &= FileSearch($full_file, $s_ext, $sep_char, True) If $check_file = 0 Then If $s_ext = '*.*' Then $allfiles &= $full_file & $sep_char If $s_ext <> '*.*' And StringTrimLeft($s_ext, 1) = StringRight($full_file, StringLen(StringTrimLeft($s_ext, 1))) Then $allfiles &= $full_file & $sep_char EndIf WEnd FileClose($search) If Not $last_line Then $allfiles = StringTrimRight($allfiles, StringLen($sep_char)) Return $allfiles EndFunc ;==>FileSearch Edited May 4, 2006 by psandu.ro
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