DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

Find A File In A List Of Dirs

  • submit to reddit
    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"
            while [#"/" = first dir] [remove dir]
            to-file dirize dir

        normalize-file: func [
            "Remove any leading slashes"
            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]