Jump to content

FileFindFirstFile


copyright
 Share

Recommended Posts

  • Developers

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...