Alteryx Designer Desktop Discussions

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

Check if file already exists and set action depending on that

kwieto
8 - Asteroid

I want to check if file with specified name and specified location exists and then perform some actions based on the output.

Location and name is based on the source file name, basically if source path is C:\Folder\Subfolder\File.xlsx then the output is C:\Folder\Subfolder\Output\File - processed.xlsx, output tab, say: summary.

Both folder location and file name may change.

For now I was trying to use the dynamic input tool in a way that it is set to open the output file and tab specified in the field from incoming stream.
It works more or less - if the file opens, then I can see records inside it and make actions based on that, if the file doesn't open (it doesn't exists or doesn't contain specified tab) then I have zero records as an output and also can take some actions.
The problem is that if it is set in that way, whenever the file/tab doesn't exist I have an error message "Cant' find the file..."

I would like to get rid of that message, but the dynamic input tool doesn't allow me to set behavior on errors.

Any Ideas how to solve that?
Or maybe there is a better way of handling that?

2 REPLIES 2
cpet13
11 - Bolide

@kwieto what might help is for you to use a Directory tool, where you choose a folder and it lists all files in the folder, then a Formula tool (IF FileName is in the list THEN 1 ELSE 0), then use a filter tool with the expression Formula Column = 1. If false, it goes to the F anchor, where you have the tools that you want to run when the file isn't present; otherwise, if the file is there, it goes to the T anchor, where you can have other tools you want to run when the file is there.

 

Does that help?

kwieto
8 - Asteroid

I thought about that, but I am reluctant to do it as since the folder path is changing I would need to put directory tool into a macro otherwise I won't be able to change the path dynamically.

 

The workflow I work on is already in a macro, and I've learned that macros within macros have limited ways to control them (i.e. I can't see control parameters of a sub-macro int the workflow where main macro is placed), so it is a bit more tricky to debug things sometimes, therefore in general I'm trying to avoid such solutions.

 

And I think filter won't be sufficient here (directory tool will not show me the tabs inside the files, so I would still need dynamic input to do that and I think it will give me an error when incoming stream will be empty)

Most probably I will need to use detour instead (if file exists, go path A, if doesn't go path B). So I would need a sub-sub-macro (first sub to control folder path, and second to control detour based on the outcome). 

Doable, but maybe there is a simplier solution?

Labels
Top Solution Authors