Alteryx Designer Desktop Discussions

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

command and bat file run fine in cmd, but error in run command tool

G1
8 - Asteroid

Hi Everyone,

 

Please could someone help me with the Run Command tool? I need to delete all backup files in a folder. I would like to use the Run Command tool to do so (I know there are other ways, but right now i'm trying the Run Command tool).

 

The command i am using to do this is del 'W:\My Documents\[remainder of file location]\test_folder\*.bak'

 

I have tried running this command by itself in CMD and it works. I have tried saving this command in a .bat file and running that in CMD and it works.

 

When I try in Alteryx using the Run Command tool it runs but nothing happens (backup files are not deleted). Can anyone see what i'm doing wrong here?

 

Note: I saw that someone answering a similar question recommended putting the space between My and Documents into  " ". Tried that and didn't work either.

 

Thanks

10 REPLIES 10
Qiu
20 - Arcturus
20 - Arcturus

@G1 
I made a simple sample and it works.
I though can not tell which part is wrong in your snapshot, it looks fine.

Is W a mapping drive? maybe you can try with the local drive?

0413-G1.PNG

flying008
14 - Magnetar

Hi, @G1 

 

First, you must determine 2 things:
1- Is your file path a local path or a network path like UNC? Because UNC paths are not well supported by cmd.
2- Does your file path contain MBCS like chinese or japanese or other special characters? Because the support for multi-byte character sets in the cmd tool of alteryx is not perfect, especially on some specific versions.
Therefore, in order to solve the above possible problems:
1- Use cmd syntax code: 

Forfiles /P "W:\My Documents\[remainder of file location]\test_folder\*.bak" /C "cmd /C if @isdir==FALSE del @path"


2- Use powershell script instead of bat script to execute your command, you will get the desired result correctly.
************
BTW, do you know the specific version number you are currently using?

SPetrie
12 - Quasar

You can see how your cmd may be erroring by adding a 'Pause" as the last command. Easily done with a union tool and text input tool. That will keep your cmd window open until you hit another key

SPetrie_0-1681395204877.png

SPetrie_1-1681395482268.png

 

 

It may help to also add the quiet and read only flags to the command

del /q /a "C:\YourFolderHere\*.bak"

 

G1
8 - Asteroid

Thanks All for your help. Let me address your suggestions in order:

 

@Qiu Thank you. I should have said that is the configuration I tried first and it did not work. Sorry, my bad. But, I tried again and it's still not working

 

@flying008 yes it is a mapped network drive. The file path contains only English characters. I tried your cmd suggestion and got the attached result. So, i guess this procedure is not do-able with Run Command. Rather annoying. I tried your suggestion of creating a power shell script but it did not like that (not a valid Win32 application). I work on a cloud desktop (AWS) so if there is some powershell setting, I do not have admin rights to alter that. Alteryx version is 2020.3.5.30242

 

@SPetrie thanks for the pause suggestion. Result attached. Can't find the location. (fyi - no need for another text input and union, just write pause on the next row down of the text input tool)

 

I am thinking from what everyone has suggested here, and the results I am getting is that this procedure is simply not do-able with Run Command from Alteryx because I am pointing it to a network drive. In which case, I'll start exploring the other methods. Thanks for everyone's replies it is appreciated!

SPetrie
12 - Quasar

Dont give up yet! This is totally doable unless there is something else Im just not seeing. I use the Run Command to move and delete files on my network drives all the time, so I know this can be done.

I dont see the /q /a in the del cmd in the pause picture. .bak files have a tendency to get the archive and hidden attributes, so cmd will bypass them without those.

You can see here how a dir cmd says there are no .bak files, but an attribute command shows otherwise because of the hidden Attribute

SPetrie_2-1681402981063.png

 

The CMD run from Alteryx will run into a similar issue.

SPetrie_1-1681402895595.png

Adding the /q and /a to the cmd will override that limitation. (q for quite mode to not ask if we really want to delete and a for read only)

Here you see the cmd now runs with no errors.

SPetrie_5-1681403230120.png

 

Now when I go back and try my dir and attrib commands, it shows the files to be deleted.

SPetrie_6-1681403353920.png

 

Other than trying those switches, you can also use the fully path for the share instead of the drive letter

\\ip address here\sharefolder instead of \\servername\sharefolder

 

G1
8 - Asteroid

@SPetrie you did it thank you! Apologies I missed the /q /a bit. And I didn't need to add in the \\ full shared path name :-))

SPetrie
12 - Quasar

Glad you go it working! Happy to help :)

Qiu
20 - Arcturus
20 - Arcturus

@SPetrie 
Nice one!

flying008
14 - Magnetar

Hi, @G1 

 

Your txt path is "W:\My Documents\[remainder of file location]\test_folder\" like a local path,

But your picture show the  "\\WorkDocs\My Documents\[remainder of file location]\test_folder\" like a network path,

because the command  fails to map the network path, so you need use complete commands syntax :

 

pushd "\\WorkDocs\My Documents\[remainder of file location]\test_folder\" && (ForFiles /M *.bak /C "cmd /c if @isdir==FALSE del @path" & popd)

 

 

Labels