Important Community update: The process for changing your account details was updated on June 25th. Learn how this impacts your Community experience and the actions we suggest you take to secure your account here.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

How to Delete a file using alteryx workflow

Lumjing
8 - Asteroid

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

4 REPLIES 4
Luke_C
17 - Castor

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"

mceleavey
17 - Castor
17 - Castor

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.



Bulien

amirsemsar
8 - Asteroid

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)

 

karenewilkins
7 - Meteor

@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

Labels