-2

I use the python code below which runs inside an Alteryx workflow. I would like to add a column so that it could list all files that are inside those folders. Any idea of how I can add this information to the code below?


from ayx import Alteryx
import pandas as pd
import numpy as np
import os
import glob

# FILE SERVER

fileDirectoryPath = Alteryx.read(r'#1')

filePathInput = fileDirectoryPath.iloc[0,0]

absPathList = glob.glob(filePathInput + '\\*\\*\\*\\*')

absPathListFiltered = [x for x in absPathList]

fullPathList = [f for f in absPathListFiltered if '.txt' not in f and '.bat' not in f]
folderList = [f.split('\\')[-1] for f in absPathListFiltered if '.txt' not in f and '.bat' not in f 
and '.ini' not in f and '.gdoc' not in f]
parentList = [f.split('\\')[-2] for f in absPathListFiltered if '.txt' not in f and '.bat' not in f 
and '.ini' not in f and '.gdoc' not in f]

np.array(fullPathList)
np.array(folderList)
np.array(parentList)

df_result = pd.DataFrame({'Files':folderList,'Parent':parentList,'FullPath':fullPathList})

Alteryx.write(df_result,1)

sophros
  • 14,672
  • 11
  • 46
  • 75

1 Answers1

2

You can directly use Alteryx Directory Tool to get all the details of your folder which will give complete meta data about the files within that directory. Just pass the Parent folder path like *.* and enable the "Include Subdirectory Option" Which will give all details. You wont need python for that. Once you have the table with directory data , you can use Filter tool to get the particular extension of files within Alteryx. Let me know if u need more help on this. You can find more details here :-

https://help.alteryx.com/current/designer/directory-tool