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