Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Find a file in a list of dirs (See related posts)

    find-file: func [
        {Based on an idea by Sunanda. Find a file in one of the specified
        dirs and return it, fully qualified.}
        dirs [block!]
        file [file!]
        /local normalize-dir normalize-file path
    ][
        normalize-dir: func [
            "Remove any leading slashes, ensure a trailing slash"
            dir
        ][
            while [#"/" = first dir] [remove dir]
            to-file dirize dir
        ]

        normalize-file: func [
            "Remove any leading slashes"
            file
        ][
            while [#"/" = first file] [remove file]
            to-file file
        ]

        foreach dir dirs [
            path: join what-dir normalize-dir form dir
            if exists? result: join path normalize-file file [return result]
        ]
    ]

You need to create an account or log in to post comments to this site.


Click here to browse all 5059 code snippets

Related Posts