How to Delete a file using alteryx workflow
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi am trying this for the first time and I have search but not getting any solution. I am trying to delete a csv file in a folder. can you please help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @Lumjing
You would either need to use the workflow events screen or the run command tool to trigger a .bat file for this. The syntax for the command is below. If you can provide a bit more info on the use case I can try to mock something up.
del "C:\...\FileName.csv"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @Lumjing ,
I would also recommend the Teknion toolkit. One of the tools basically packages up the .bat process outlined by @Luke_C into a tool, so you don't need to write these processes. You can also use the tools to move files around, connect to sFTP, S3 etc.
Very useful.
You can download them HERE.
M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Alternatively you can use the OS library in Python. This is is included in all the versions I have worked with from 2019 up.
You need to point to a directory or feed the python tool full paths and it should do the job. This will also validate that it has been deleted.
For an intro you can look at this video: https://www.youtube.com/watch?v=MNwA-EBWWao
This is the code snippet that you can copy. Uses norm path to clean up the path of any double slashes and formats it correctly. Then uses remove to purge the files and then finally exists to validate the deletion and spits out every one deleted in the Alteryx results.
from ayx import Package
from ayx import Alteryx
import pandas as pd
import os
def delete_files(a):
mt=[]
mt2=[]
fullpath=a['fullpath'].tolist()
fullpath=[os.path.normpath(x) for x in fullpath]
for each in fullpath:
mt=[os.path.basename(each) for each in fullpath]
os.remove(each)
mt2=[os.path.exists(each) for each in fullpath]
dicty={'FILES':[x for x in mt],'STILL_AVAIL':[y for y in mt2]}
output=pd.DataFrame.from_dict(dicty)
Alteryx.write(output,1)
df=Alteryx.read("#1")
delete_files(df)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@amirsemsar Great tutorial.... I probably need to take some Python classes to get more familiar with the "language". The tutorial definitely helped me to delete files, in lieu of using a command tool. Thank you
