hot202 Posted September 3, 2010 Share Posted September 3, 2010 is there anyway to use FileFindFirstFile with multiple extension so i can use it to find say .jpg and .bmp? Link to comment Share on other sites More sharing options...
Tvern Posted September 3, 2010 Share Posted September 3, 2010 I don't think you can. However if you just make it return any file it's easy to then check for multiple extentions with StringRegExp(). Link to comment Share on other sites More sharing options...
hot202 Posted September 3, 2010 Author Share Posted September 3, 2010 so i would do a IF in the while loop? to see if its a .bmp or a .jpg? Link to comment Share on other sites More sharing options...
Tvern Posted September 3, 2010 Share Posted September 3, 2010 Yeah and then you can just Continueloop if the extention doesn't match. Link to comment Share on other sites More sharing options...
hot202 Posted September 3, 2010 Author Share Posted September 3, 2010 i cant seem to get it working $search = FileFindFirstFile($nm_dir & '\' & $event_value & "\" & "*.*") 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 $ConstR = StringRegExpReplace($file, "^.*\\", "") $test = StringMid($ConstR, StringInStr($ConstR, ".") + StringLen(".")) Switch $test Case "bmp" MsgBox(1,"test",$file & ".bmp") Case "jpg" MsgBox(1,"test",$file & ".jpg") EndSwitch WEnd FileClose($search) Link to comment Share on other sites More sharing options...
Tvern Posted September 3, 2010 Share Posted September 3, 2010 Try one of the following with the return from FileFindNextFile(): StringRegExp($file, ".*(bmp|jpg)\z") ;Returns 1 if *.bmp, or *.jpg. Returns 0 if not. StringRight($file,4) ;Returns the last 4 characters of the filename for use with your switch. (add a period to your comparrison strings though) You might want to double check to make sure you don't get a possitive on a folder it it has .jpg, or .bmp at the end. (daft I know) Breakdown of the pattern: ".*(bmp|jpg)\z" 1: . ;match any character 2: * ;repeat 1 zero, or more times 3: (bmp|jpg) ;match bmp Or JPG (I'm not sure how or knows what's part of the statements so I put brackets around it just to be sure. Seems to work without) 4: \z ;match at end of file only. Link to comment Share on other sites More sharing options...
hot202 Posted September 3, 2010 Author Share Posted September 3, 2010 thank man i wasnt sure about using StringRight($file,4) incase the extension is more then 3 but there aint any in windows are there. Link to comment Share on other sites More sharing options...
Tvern Posted September 3, 2010 Share Posted September 3, 2010 (edited) There are plenty of longer extensions (docx, xlsx, java, etc), but as long as you don't want those extentions to return a match that doesn't matter. edit: If you want to return the full extention regardless of length you can use: $pos = StringInStr($file, ".", 0, -1) ;search for last period If $pos Then ;file has an extention $test = StringRight($file, StringLen($file) - $pos) ;get the extention Else $test = "" ;create a blank string if the file has no extention EndIf Note that this doesn't return the leading "." as it's not needed anymore. Edited September 3, 2010 by Tvern 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