How to resolve the algorithm File extension is in extensions list step by step in the Phix programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm File extension is in extensions list step by step in the Phix programming language

Table of Contents

Problem Statement

Filename extensions are a rudimentary but commonly used way of identifying files types.

Given an arbitrary filename and a list of extensions, tell whether the filename has one of those extensions.

Notes:

The following test cases all assume this list of extensions:   zip, rar, 7z, gz, archive, A## If your solution does the extra credit requirement, add tar.bz2 to the list of extensions, and check the following additional test cases: Checking if a file is in a certain category of file formats with known extensions (e.g. archive files, or image files) is a common problem in practice, and may be approached differently from extracting and outputting an arbitrary extension (see e.g. FileNameExtensionFilter in Java). It also requires less assumptions about the format of an extension, because the calling code can decide what extensions are valid. For these reasons, this task exists in addition to the Extract file extension task.

Let's start with the solution: