Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

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

Delete Excel Output Files Older than 5 Days using Event/BAT file

JPSeagull
8 - Asteroid

Hi. I have been using a simple BAT file in the Events of the Workflow Configuration to remove the *.xlsx.bak files with no problems. Now I am being asked to also remove all Excel file 5 days and older from the same folder.

 

My current BAT file has this: 

del "\\main\obx\lifeline\*.xlsx.bak"

 

Would I be wise to add a second event BAT file and if so, what would be the logic to delete anything five days and older? I have tried different suggestions with FORFILEs and I get errors running the file. 

6 REPLIES 6
Raj
16 - Nebula

@JPSeagull try using Command Prompt tool. That will work.

JPSeagull
8 - Asteroid

@Raj - Yes, I am exploring that tool, but I am trying to find the logic/coding for specifying 5 days and older to delete files from a shared folder.

Raj
16 - Nebula

@JPSeagull 
your command should look soemthing like this
@echo off setlocal REM Change directory to the folder where your Excel files are located cd /d "\\main\obx\lifeline\" REM Delete Excel files older than 5 days forfiles /p "\\main\obx\lifeline\" /m "*.xlsx" /d -5 /c "cmd /c del @file" endlocal

also please reffer the attached example to make the configurations.

JPSeagull
8 - Asteroid

@raj - the issue is that I load the workflow to our Gallery and it seems that there is a UNC issue and the Gallery doesn't run the FORFILES command.

 

Like I said, it perfectly runs the batch file to delete the .BAK files. I was hoping to modify that same command without using forfiles. I can load a mockup workflow, but not sure how it will help if the events is pointing to batch file in another shared folder location.

danilang
19 - Altair
19 - Altair

Hi @JPSeagull 

 

One of the ways is to use a directory tool and filter out all the files newer than 5-days.  Build a batch file with the following structure and pass it to a Command tool

 

del "\\main\obx\lifeline\Oldfile1.xlsx"

del "\\main\obx\lifeline\Oldfile2.xlsx"

del "\\main\obx\lifeline\Oldfile3.xlsx"

 

Dan

JPSeagull
8 - Asteroid

@danilang Thank you! That is what I did. I used command tool and created a batch file. Works perfectly!

Labels