Sign in to follow this  
Followers 0
raven096

File Name Filter Search

5 posts in this topic

I'm new to AutoIt so I need some help here, I'm looking for a way to look for a word within a file name, it might be in the beginning, middle or end of the file:

Hello*.*

*Hello*.*

*Hello.*

I've found some file searches based on a mask but not a full name. If I was writing in perl I'd just:

$filesearch =~ /Hello/i;

But I'm trying to create a GUI interface and I find AutoIt much easier to build in, so if anyone has a suggestion or a function it would be very helpful.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Look up StringInStr in the help

If StringInStr($filesearch, 'Hello') then
; do what you need to do
endif
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Sorry, I guess what I really am looking for is a function to search a directory for a file with a specific word within the filename thats also not case sensitive.

Edited by raven096

Share this post


Link to post
Share on other sites

Sorry, I guess what I really am looking for is a function to search a directory for a file with a specific word within the filename thats also not case sensitive.

You could use FileFindFirstFile() and FileFindNextFile() to build a list of files within a specified directory and then search each line of the list for a substring.

Alternatively you could call DOS to do this for you (untested; may need to edit slightly):

local $fileSpec = "C:\My Folder\*apple*"
local $tempFile = @tempDir & "\listing.txt"

runWait(@comSpec & '/c dir /b /s "' & $fileSpec & '" > "' & $tempFile & '"', "", @SW_HIDE)

; code to process the listing would go here

fileDelete($tempFile)

Regards,

Alex Peters

Share this post


Link to post
Share on other sites

this works well:

$AllPcFiles = FileFindFirstFile("\\server\log$\AdminAudit\*.txt")

While 1
   $filename = FileFindNextFile($AllPcFiles)
   If @error Then ExitLoop
   If $filename = "" Then ExitLoop
   $FileRead = Fileopen("\\server\log$\AdminAudit\" & $filename, 0) 
  ; do what ever here
   FileClose($fileRead)
WEnd

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  
Followers 0