Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.
Alteryx is here to help you solve your biggest data challenges. Read about the new Virtual Solution Center here.

Run Command Error 1 when trying to delete files with a batch file

Highlighted
7 - Meteor

I am using the run command tool to write and run a batch file that will delete old files from a shared drive. This workflow writes the file correctly and I can even run it by double-clicking. However, the workflow cannot run the very same file. It gives me an Error code 1. I have already searched Alteryx Community for help and found a few things but nothing I have found has helped me resolve this issue.

 RunCommand.PNG

Here is what is in my batch file. It is just one line that deletes all CSVs that are more than 1 day old.

forfiles /p %~dp0 /s /m *.CSV /d -1 /c "cmd /c DEL /Q @PATH"

 

Thanks in advance for your help.

 

Jeff

Highlighted
8 - Asteroid

Hello,

 

This isn't an alteryx issue. Your bat is failing. Have you tried running the batch on its own?

 

Maybe fix the dir to a test dir and put in a /k instead of /c on cmd to stop the prompt from closing (see below)

 

 

forfiles /p "C:\YOUR DIR" /s /m *.* /D -1 /C "cmd /k del @path"

Highlighted
7 - Meteor

Yes, like I said previously, the bat runs perfectly as-is on its own. When I changed from /c to /k it failed to delete the files and left the command window open.

Since everything is on a shared drive and UNC paths do not work in a batch file, I'm using the %~dp0 instead of an absolute path. Any reason I can't or shouldn't use the %~dp0 variable?

 

Thank you

Highlighted
8 - Asteroid
EDIT: The bat fails if there is nothing to delete. This is probably it! Try again tomorrow
little edit: There is no real reason to not use %~dp0 I just like having an explicitly name folder to dump old files into during testing 
 
Hmm this worked for me. The first forfiles was just for initial debugging. You could get rid of it.
 
 
echo I eat files
forfiles /p "c:\Users\william.bowman\Downloads" /m *.csv /d -5 /c "cmd /c echo @path @fdate"
echo Will be deleted
forfiles /p "c:\Users\william.bowman\Downloads" /m *.csv /d -5 /c "cmd /c del /s @path"
 
Capture.PNG
Highlighted
7 - Meteor

Our posts may have crossed paths so FYI I just updated my last post with better explanation.. in case you missed it.

 

That said, I think I need the forfiles because I'm deleting a batch of files from the previous day. What's happening is that I have a separate workflow that creates the files with a timestamp in the name that gets generated every 20 minutes. This workflow runs 24/7, so... lots of CSV's being generated. Those files get sent via FTP to another location. Once the FTP is done, I can delete the files; which needs to happen because with a file being generated every 20 minutes the drive will fill up pretty quickly.

Highlighted
8 - Asteroid

Hey so if it still doesn't work and there are files that should be deleted but aren't...

 

I looked into it a little more and it appears that Alteryx runs a copy of the bat file from a special location inside of it's own environment (or something to that effect). So specifying the full path might help because the local wd from %~dp0 is going to be inside alteryx (where there are no CSVs which will result in none found failure)

 

If that fails, it my be worth making sure none of these files are locked by other processes if you are constantly creating/transferring. But it should be skipping over all of those files from metadata so unlikely.

Labels