Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Hi,
How would I go about clearing the contents of a managed folder in a recipe?
Best.
Hi @vishet,
I think it will depend somehow in your particular use case:
and in this way you will be sure that every time you refresh the contents of the managed folder all the data will be downloaded again, and all any other extra files will be erased.
import dataiku
import os
import shutil
path_to_folder = dataiku.Folder('foldername').get_path()
# took from a kite example
list_dir = os.listdir(path_to_folder)
for filename in list_dir:
file_path = os.path.join(path_to_folder, filename)
# If the element is a file
if os.path.isfile(file_path) or os.path.islink(file_path):
print("deleting file:", file_path)
os.unlink(file_path)
# In case is a folder
elif os.path.isdir(file_path):
print("deleting folder:", file_path)
shutil.rmtree(file_path)
โ
Hope one of these solutions helps!
I.
Hi @vishet,
I think it will depend somehow in your particular use case:
and in this way you will be sure that every time you refresh the contents of the managed folder all the data will be downloaded again, and all any other extra files will be erased.
import dataiku
import os
import shutil
path_to_folder = dataiku.Folder('foldername').get_path()
# took from a kite example
list_dir = os.listdir(path_to_folder)
for filename in list_dir:
file_path = os.path.join(path_to_folder, filename)
# If the element is a file
if os.path.isfile(file_path) or os.path.islink(file_path):
print("deleting file:", file_path)
os.unlink(file_path)
# In case is a folder
elif os.path.isdir(file_path):
print("deleting folder:", file_path)
shutil.rmtree(file_path)
โ
Hope one of these solutions helps!
I.