Is there a way to use the directory tool and output the filename as a field?
I have daily files in one folder going back with filename e,g "alteryx-20200813" and I want the datefield to be a column.
The object is to append all the end of month files to one file.
I have read many posts in the forum and the best solution I have found is to use the input tool and the *, but the files are quite huge and many so the runtime will be quite bad.
Anyone know a better solution?
解決済! 解決策の投稿を見る。
Hi @Bralex
Below is a sample workflow that reads the list of files in a folder with a directory tool. It assumes the filenames are alteryx-20200731.csv; alteryx-20200730.csv; alteryx-20200729.csv; etc.
It then extracts the date and breaks it up into year, month, day. Now you can sort by Year, Month, Day (changing the sort order for day to descending) and then use the Sample tool where you Group by Year and Month and select the 1st record.
This gives you the file for the last day of every month.
If you run my workflow, you'll get an error since you won't have the folder I'm referring to, so I added the output of my Directory tool in a Text Input tool, so that you can see how it works.
Thank you for your replies, much appreciated.
What I am really looking for is to get the filename to a field, or as a column.
So after selecting the relevant files, as your solutions above is perfect for, then output the filename as a column in the dataset.
With the solution that @wwatson proposed, where the list of files are loaded into one dataset with the dynamic input tool, you can select the option in the template file setup in the dynaimc input tool to output the file name as a field.
You can either select filename or fullpath.
Thank you both so much, really appreciate it.