Jump to content

Run lines of script if X is met otherwise ignore those lines


Oyvlei
 Share

Recommended Posts

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

Look in the help for

Select

Switch

and study the examples for them.

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

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! :D 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 :D

Local $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 by Oyvlei
Link to comment
Share on other sites

Oyvlei,

I would organize the code as follows...

local $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

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

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...