How to delete files in Managed Folders if Python process is running remotely?

kentnardGaleria
Level 3
How to delete files in Managed Folders if Python process is running remotely?

Hello, 

I have created a managed folder through Python code whose process is running remotely and direct access to folder is not possible. I have successfully made a Python code with 'xlsxwriter' engine to create files (more than 50) and some folders inside the managed folder without problems. 

Now I want to remove all existing files that are inside the managed folder. I know it is possible to do it manually in the managed folder, but deleting more than 50 folders manually is not reasonable. Additionally, I was able to get the list of files inside the folder through the module "list_paths_in_partition()", but I could not proceed in deleting them. So, how could I achieve this without knowing the path of the files? Thanks in advance.

 

Best regards,

Kentnard


Operating system used: Windows

0 Kudos
4 Replies
Turribeach

"but I could not proceed in deleting them" => Explain in detail, post code sample, give error codes, etc, etc. 

0 Kudos
kentnardGaleria
Level 3
Author

Hi, thanks for the reply. 

My idea was to use the os.remove() to remove all the files. However, it is not possible, since the Python process is running remotely. (See Screenshot2) In the attached screenshot, I have a list of the files inside the folder, and I am using the last file in the list as an example. I want to check it's existance first, but it doesn't exist, because obviously the file path is not complete. (See Screenshot1)

I have no idea what alternative methods can be applied here to delete the files. 

Thanks in advance

0 Kudos

You can use the delete_path() method:

 

output_folder.delete_path('/Test3_400036.xlsx'๏ผ‰

 

https://developer.dataiku.com/latest/api-reference/python/managed-folders.html#dataiku.Folder.delete...

 

 

kentnardGaleria
Level 3
Author

Thank you for the reply! The code works really well.

0 Kudos