Add the filename to a table - for each record
- 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
I have daily data come in and need to make one of the columns the filename. i.e. reach record in the table would have "todaysfile_02162015.txt" or whatever the file name is. I can use "Field Info" to get the filename but then I can't link it back into the data so that every record has the filename. Note: it's the same filename for all the records.
Solved! Go to Solution.
- Labels:
- Preparation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Cheers
Adam
https://www.linkedin.com/in/adriley/
- 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
I am not seeing an option under the InOut tool menu for "Output File Name as Field".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Galdous,
I believe Adam is pointing to the Input Data Tool in the IN/OUT Category. See picture attached.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
David,
If you choose "Full Path" (see below), this will give you the entire path. You can then use reg ex tools/formulas to strip out just the file name. I like to use the Text to Columns tool delimited on the "\". That way I just use a select tool after to take only the file name field. Saves from having to figure out the reg ex expression.
Here's an example:
Input tool:
Text To Columns Tool:
Select Tool:
Final result:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I see. I was looking in the wrong place. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
You're welcome!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
This is a great solution when the input is a flat file. What if the input is a database file? I don't see the "Output File Name as Field" when reading a database file!
I'm using ODBC connection to read a table that is sitting in MySQL and would like to have the database name as a new field. The database name is the date that the file was crated, and I would like to add it to every row. Exaclty the same problem as David's, but with database file.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Oh - yes, that's correct - the file name output option will not apply to ODBCs.
In this case, create an extra stream coming from your input that connect to the Field Info tool. Then use a select tool after that and choose only the "Source" field. That will have your database name. It might look ugly, so you may have to parse it out using Reg Ex or something like that.
Once you have that, you can just use an append tool to append that field to your entire dataset as an extra column.
