copyright 0 Posted September 19, 2004 How do I search a string within file names in a directory and return the first result into a $variable ? Share this post Link to post Share on other sites
Jos 2,165 Posted September 19, 2004 How do I search a string within file names in a directory and return the first result into a $variable ? <{POST_SNAPBACK}>heres the helpfile example with some modifications: ; Shows the filenames of all files in the current directory, note that "." and ".." are returned. $search = FileFindFirstFile("*.*") $Sstr = "test" ; string to search ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If StringInStr($file, $Sstr) Then MsgBox(4096, "File:", $file) ExitLoop EndIf Wend SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Share this post Link to post Share on other sites
copyright 0 Posted September 20, 2004 heres the helpfile example with some modifications: ; Shows the filenames of all files in the current directory, note that "." and ".." are returned. $search = FileFindFirstFile("*.*") $Sstr = "test" ; string to search ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If StringInStr($file, $Sstr) Then MsgBox(4096, "File:", $file) ExitLoop EndIf Wend <{POST_SNAPBACK}>there a way to add a specified directory to search in ? Share this post Link to post Share on other sites
ezzetabi 3 Posted September 20, 2004 RTFM Change @WorkingDir before that code. $dir = 'The dir where seek' FileChangeDir($Dir) $search = FileFindFirstFile("*.*") $Sstr = "test" ; string to search ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If StringInStr($file, $Sstr) Then MsgBox(4096, "File:", $file) ExitLoop EndIf Wend Share this post Link to post Share on other sites
copyright 0 Posted September 20, 2004 RTFM Change @WorkingDir before that code. $dir = 'The dir where seek' FileChangeDir($Dir) $search = FileFindFirstFile("*.*") $Sstr = "test" ; string to search ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If StringInStr($file, $Sstr) Then MsgBox(4096, "File:", $file) ExitLoop EndIf Wend <{POST_SNAPBACK}>thanks for the quick reply.. we'll see if it works.. . Share this post Link to post Share on other sites