Deleting files

110 views
Skip to first unread message

José Eloy

unread,
Mar 5, 2021, 1:08:41 PM3/5/21
to web2py-users

Hi there.

I made a Web2py app. This app create pdf reports, which are opened by the Web Browser. The pdf files are saved in Download folder of the user. Is there any way to delete these files from Download directory? I tried several ways and I get  <class 'PermissionError'> [WinError 5] Denied access:in  'c:\\Users\\xxxxx\\Downloads' . The app runs behind IIS server.

The code i'm using in a controller is:

    sistema = platform.system()
    if sistema == "Windows":
        rutaDescargas = Path(r"c:\Users\xxxx\Downloads")

        archivosRecibos = rutaDescargas.glob("*.pdf")
        for archivo in archivosRecibos:
            os.remove(archivo)

xxx represents the name of user on compuer user

The app is running in a small office, in internal network, no Internet server.

Thanks.

Dave S

unread,
Mar 9, 2021, 5:03:29 AM3/9/21
to web2py-users
On Friday, March 5, 2021 at 10:08:41 AM UTC-8 José Eloy wrote:

Hi there.

I made a Web2py app. This app create pdf reports, which are opened by the Web Browser. The pdf files are saved in Download folder of the user. Is there any way to delete these files from Download directory? I tried several ways and I get  <class 'PermissionError'> [WinError 5] Denied access:in  'c:\\Users\\xxxxx\\Downloads' . The app runs behind IIS server.

Browsers generally limit a page's direct access to the client file system as a security measure.  You are not supposed to be able to put files in arbitrary places (to avoid malicious code downloads) or read files outside a special store (to avoid data harvesting of personal or proprietary data) or to delete files outside of the special store.

You can change the disposition header to control whether a file (the PDF report, in your case) is to be saved or only displayed.  (In the latter case, it's generally still possible for the user to choose to save the file.)

/dps

Reply all
Reply to author
Forward
0 new messages