Jump to content
Sign in to follow this  
copyright

FileFindFirstFile

Recommended Posts

copyright

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

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        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

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

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

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

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
Sign in to follow this  

×