Oyvlei Posted December 23, 2013 Share Posted December 23, 2013 Hello so I want to search for a file starting with test*.txt in a certain folder and if it can find that file it will run the next few lines, if it can't find that file it will jump over those lines. Will really appriciate it if someone can help me with this as I am struggeling. Example: Search for a file containing "train" in set directory, if true run lines below, if false jump over lines. lines to run if a file with "train" is found lines to run if a file with "train" is found Search for a file containing "car" in set directory, if true run lines below, if false jump over next lines. lines to run if a file with "car" is found lines to run if a file with "car" is found Search for a file containing "boat" in set directory, if true run lines below, if false jump over next lines. lines to run if a file with "boat" is found lines to run if a file with "boat" is found Link to comment Share on other sites More sharing options...
martin Posted December 23, 2013 Share Posted December 23, 2013 Look in the help for Select Switch and study the examples for them. Oyvlei 1 Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
somdcomputerguy Posted December 23, 2013 Share Posted December 23, 2013 Read about the two FileFind functions in the Help file too. Oyvlei 1 - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Oyvlei Posted December 24, 2013 Author Share Posted December 24, 2013 (edited) Look in the help for Select Switch and study the examples for them. Read about the two FileFind functions in the Help file too. Thanks guys! How do I make it start fresh on line 20 after answer 1 and -1? Like if it cant find the file it will start over on line 20, and if it finds the file it will create the folder then start fresh on line 20 also? edit: think I figured it out expandcollapse popupLocal $search = FileFindFirstFile(@UserProfileDir & "\test folder\boat*.txt") If $search = -1 Then EndIf While 1 Local $file = FileFindNextFile($search) If @error Then ExitLoop DirCreate(@UserProfileDir & "\test folder\boat\" ) WEnd FileClose($search) Local $search = FileFindFirstFile(@UserProfileDir & "\test folder\car*.txt") If $search = -1 Then EndIf While 1 Local $file = FileFindNextFile($search) If @error Then ExitLoop DirCreate(@UserProfileDir & "\test folder\car\" ) WEnd FileClose($search) Exit Edited December 24, 2013 by Oyvlei Link to comment Share on other sites More sharing options...
kylomas Posted December 24, 2013 Share Posted December 24, 2013 Oyvlei, I would organize the code as follows... expandcollapse popuplocal $path = @WorkingDir Local $search = FileFindFirstFile($path & "\test folder\*.txt") If $Search = -1 Then MsgBox(0, "", "Error: No files/directories matched the search pattern.") exit EndIf while 1 Local $file = FileFindNextFile($search) If @error Then ExitLoop switch not 0 case stringinstr($file,'train') if not fileexists($path & "\test folder\train\") then DirCreate($path & "\test folder\train\" ) ; ; do other train related processing ; case stringinstr($file,'car') if not fileexists($path & "\test folder\car\") then DirCreate($path & "\test folder\car\" ) ; ; do other car related processing ; case stringinstr($file,'boat') if not fileexists($path & "\test folder\boat\") then DirCreate($path & "\test folder\boat\" ) ; ; do other boat related processing ; case Else ; ; if necessary do no match type of processing ; endswitch wend FileClose($search) kylomas Oyvlei 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill 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