Sign in to follow this  
Followers 0
Oyvlei

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

5 posts in this topic

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

Share this post


Link to post
Share on other sites



Look in the help for

Select

Switch

and study the examples for them.

1 person likes this

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.

Share this post


Link to post
Share on other sites

Read about the two FileFind functions in the Help file too.

1 person likes this

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

#4 ·  Posted (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! :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

Share this post


Link to post
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

1 person likes this

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

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