copyright Posted September 19, 2004 Share Posted September 19, 2004 How do I search a string within file names in a directory and return the first result into a $variable ? Link to comment Share on other sites More sharing options...
Developers Jos Posted September 19, 2004 Developers Share 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. Link to comment Share on other sites More sharing options...
copyright Posted September 20, 2004 Author Share 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 ? Link to comment Share on other sites More sharing options...
ezzetabi Posted September 20, 2004 Share 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 Link to comment Share on other sites More sharing options...
copyright Posted September 20, 2004 Author Share 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.. . 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