Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

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

Iterative macro to compare files

Radhika
6 - Meteoroid

Hi 

 

I have a scenario where I need some help.

 

I have to compare filenames with their file path through iterative macro. I have certain files which should be placed in their correct folders, My requirement is to check if the files are placed at their correct location or not. The file names are given on the basis of their folder structure.

 

Main folder has many folders A1,A2.....so on

Each A1 folder has subfolders B1,B2.....so on

Each B1 folder has subfolders C1,C2.....so on

Each C1 folder has subfolders D1,D2.....so on

Each D1 folder has subfolders E1,E2.....so on

Each E1 folder has files F1,F2......so on

 

Folder hierarchy A1>B1>C1>D1>E1>F1

F1,F2 are files

 

E1 folder naming (based on its folder hierarchy):

F1 file has naming convention as A1_B1_C1_D1_E1_ddmmyyyy.csv ,

F2 will have name A1_B1_C1_D1_E1_ddmmyyyy.csv where ddmmyyyy will be on daily basis.

 

E2 folder naming :

F1 file has naming convention as A1_B1_C1_D1_E2_ddmmyyyy.csv ,

F2 will have name A1_B1_C1_D1_E2_ddmmyyyy.csv where ddmmyyyy will be on daily basis.

 

To do : I have to compare the filenames with their respective paths if the files exist in the correct folder or not.

For example -

File F1 in E1 will have name -  A1_B1_C1_D1_E1_ddmmyyyy.csv 

File F2 in E1 will have name -  A1_B1_C1_D1_E1_ddmmyyyy.csv 

 

From this I will have to fetch filename A1_B1_C1_D1_E1 from each file and I need to compare it with its path 

A1\B1\C1\D1\E1 

as the name matches with its folder structure/hierarchy which concludes file is placed in correct folder and it will send mail to a group of people

 if there is a file named A1_B1_C1_D1_E2 in A1\B1\C1\D1\E1 path it should not be placed at this path so it will send mail to another group of people,

 

I need an iterative macro to check and compare all files till it covers all A folders.

Can anyone help on this scenario?

Thanks in advance.

 

1 REPLY 1
chukleswk
11 - Bolide

@Radhika 

You don't need an iterative macro in order to do this. This can actually be accomplished quite simply with the Directory tool and some follow-on tools

  • The Directory tool will pull all of the file information for what's in the directory that you identified as long as you have access to the directory.
  • You then will parse out the Directory column into the appropriate number of folders for your job
  • You will want to also parse down your file name into the correct number of delimiters
  • After that, it is a simple if statement that will check that Directory Path 1 = Filename Path 1
  • From there you can filter out the files that are in the wrong path and generate out the emails that need to be sent.

I have attached the workflow and test files so that you can try it out. The test files are just empty CSV files.

 

2023-02-02_10-08-15.png

Labels