Reading file name from file_loader without extension

I’m simply trying to read the file name from the file_loader ‘wihout’ reading the extension through a button click. How can i do this?

Currently i’m reading the file name like this:

    file = self.file_loader_1.file
    name = file.name

And i’m getting the output “a.zip”. But i ‘only’ want to read a from a.zip

I tried to remove .zip through the python code on the click of a button on the server side like this:

    print("BEFORE= " ,name)
    name.replace('.zip', ' ')
    print("AFTER= " ,name)

But it didn’t work. I got the following output:

BEFORE= a.zip
AFTER= a.zip

Clone link:
https://anvil.works/build#clone:36ZIQWEAVI3ZC4T7=VCBQ3O6XQUIYJCMGZJ7LAMLR

Strings in Python are immutable, which means that the replace method returns you a modified copy of the string, it doesn’t change the original string. So you need to assign the copy back into the name variable.

name = name.replace('.zip', ' ')

1 Like

Thank You so much for the quick response!!

Also, is there any way to restrict the file_loader to choose ‘only’ zip files?

For the image selection it is: image/* But not sure for the zip files.

The filter is a MIME type, so maybe application/zip ?

2 Likes

It worked!! Thanks again :smile:

1 Like