Output filename and get latest file in month
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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?
Solved! Go to Solution.
- Labels:
- Input
- Tips and Tricks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thank you both so much, really appreciate it.
