# FileReader and FileWriter for 2 classes

**URL:** <https://discourse.slicer.org/t/filereader-and-filewriter-for-2-classes/32319>\
**Category:** Support\
**Created:** [October 19, 2023, 2:47am UTC](https://discourse.slicer.org/t/filereader-and-filewriter-for-2-classes/32319 "2023-10-19T02:47:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rphellan2210](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rphellan2210/32/79570_2.png) [@rphellan2210](https://discourse.slicer.org/u/rphellan2210)\
**Post date:** [October 19, 2023, 2:47am UTC](https://discourse.slicer.org/t/filereader-and-filewriter-for-2-classes/32319/1 "2023-10-19T02:47:14Z")

</div>

Hello,

I have used the [ModuleName] FileReader and [ModuleName] FileWriter before to allow drag and drop of a file with a specific extension into my module. However, I cannot figure out how to add more than one file extension. Do you have any example of this?

The code below shows a simple FileReader, but because the name of the class matches the name of the module, I cannot add more than one extension.

```auto
class MyModuleFileReader:

    def __init__ (self, parent):
        self.parent = parent

    def description(self):
        return 'Specific type'

    def fileType(self):
        return 'Specific'

    def extensions(self):
        return ['Specific (*.spc)']

    def canLoadFile(self, filePath):
        return filePath.endswith('.spc')

    def load(self, properties):
        try:
            pass
        except Exception as e:
            logging.error('Failed to load file: ' + str(e))
            import traceback
            traceback.print_exc()
            return False

        return True

```

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [October 19, 2023, 2:44pm UTC](https://discourse.slicer.org/t/filereader-and-filewriter-for-2-classes/32319/2 "2023-10-19T14:44:43Z")

</div>

You should be able to use a format like this:

> <https://github.com/Slicer/Slicer/blob/d47277045f3cbc6db69953c1f118739005350e5d/Modules/Loadable/Transforms/qSlicerTransformsReader.cxx#L85>

---

<div class="post-metadata">

**Author:** ![rphellan2210](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rphellan2210/32/79570_2.png) [@rphellan2210](https://discourse.slicer.org/u/rphellan2210)\
**Post date:** [October 19, 2023, 9:26pm UTC](https://discourse.slicer.org/t/filereader-and-filewriter-for-2-classes/32319/3 "2023-10-19T21:26:22Z")

</div>

Oh this allows me to add more than one extension for the same type of file. But, is it possible to also add more than one file type?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [October 19, 2023, 9:28pm UTC](https://discourse.slicer.org/t/filereader-and-filewriter-for-2-classes/32319/4 "2023-10-19T21:28:09Z")

</div>

I believe it follows the conventions described here:

> **[QFileDialog Class | Qt Widgets 6.6.0](https://doc.qt.io/qt-5/qfiledialog.html#details)**
>
> The QFileDialog class provides a dialog that allow users to select files or directories.
