How can I insert the file name into the file I am manipulating. I would like to automate this process over a 1000 files, but I need to get the file name into the contents of the file. Any help would be appreciated.
Thanks,
Dave
Inserting file name into the file
Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators
- DataMystic Support
- Site Admin
- Posts: 2227
- Joined: Mon Jun 30, 2003 12:32 pm
- Location: Melbourne, Australia
- Contact:
Hi,
I've got a similar kind of problem but rather than wanting to insert the filename into the file contents I would like to get the filename into the output files.
Here's an overview:
I have input filename Moz.txt (the input filename changes) and have a custom filter that processes this file to extract different data and sorts this data into different files depending on the content of each line. I extract the data by restricting to matching lines then merging the restricted lines to an output file (is there a different way of doing that?). I end up with 4 files:
output1.txt
output2.txt
output3.txt
output4.txt
However as I run the same filter very often and on a large number of input files I want to add in the name of the input file to the output file's name.
So for the example above I would like the output files to be named:
Moz-output1.txt
Moz-output2.txt
Moz-output3.txt
Moz-output4.txt
I have tried the global variable @inputfilename but the variabe is not parsed when it's in the "Merge to File" filter filename section, and after rading the help section and forum I can't seem to find any way of doing this.
As a bonus I would also like to count the number of lines in each of my output files and produce an "analysis" file, so an example contents for the above may be:
Filename: Moz-Analysis.txt
---==--
Analysis of: Moz.txt
Moz-output1.txt - 554 lines
Moz-output2.txt - 4433 lines
Moz-output3.txt - 399 lines
Moz-output4.txt - 0 lines
Lines not valid: 32
--==--
The last bit would be because 32 lines didn't match any of my filter and so there would be 32 lines left in the original file - Moz.txt.
Thanks for any help.
Cheers,
Moz
I've got a similar kind of problem but rather than wanting to insert the filename into the file contents I would like to get the filename into the output files.
Here's an overview:
I have input filename Moz.txt (the input filename changes) and have a custom filter that processes this file to extract different data and sorts this data into different files depending on the content of each line. I extract the data by restricting to matching lines then merging the restricted lines to an output file (is there a different way of doing that?). I end up with 4 files:
output1.txt
output2.txt
output3.txt
output4.txt
However as I run the same filter very often and on a large number of input files I want to add in the name of the input file to the output file's name.
So for the example above I would like the output files to be named:
Moz-output1.txt
Moz-output2.txt
Moz-output3.txt
Moz-output4.txt
I have tried the global variable @inputfilename but the variabe is not parsed when it's in the "Merge to File" filter filename section, and after rading the help section and forum I can't seem to find any way of doing this.
As a bonus I would also like to count the number of lines in each of my output files and produce an "analysis" file, so an example contents for the above may be:
Filename: Moz-Analysis.txt
---==--
Analysis of: Moz.txt
Moz-output1.txt - 554 lines
Moz-output2.txt - 4433 lines
Moz-output3.txt - 399 lines
Moz-output4.txt - 0 lines
Lines not valid: 32
--==--
The last bit would be because 32 lines didn't match any of my filter and so there would be 32 lines left in the original file - Moz.txt.
Thanks for any help.
Cheers,
Moz
- DataMystic Support
- Site Admin
- Posts: 2227
- Joined: Mon Jun 30, 2003 12:32 pm
- Location: Melbourne, Australia
- Contact:
The easiest way to do this would be to use File\Export to VBScript to generate a scriptable version of the filter, then programmatically set the filename based on the input filename, for each file.
Other than that, there's no easy way to do it, unless you wrote your own Output Filter using VBScript, which could query the current filename. This is not that hard to do.
Other than that, there's no easy way to do it, unless you wrote your own Output Filter using VBScript, which could query the current filename. This is not that hard to do.
Hi Simon,Simon Carter wrote:Other than that, there's no easy way to do it, unless you wrote your own Output Filter using VBScript, which could query the current filename. This is not that hard to do.
OK thanks for the reply- I'll see if I can work out how to do that, but my programming skills aren't particularly brilliant!
Any ideas on the second bit - generating a "summary" or "analysis" file?
Cheers,
Moz
- DataMystic Support
- Site Admin
- Posts: 2227
- Joined: Mon Jun 30, 2003 12:32 pm
- Location: Melbourne, Australia
- Contact:
Hi Moz,
Again, this can be done with a VBScript. You'll need to use global variables to keep track of the number of lines written to each file, then simply write this data out to a new file in the endJob function. See
for an example.
Again, this can be done with a VBScript. You'll need to use global variables to keep track of the number of lines written to each file, then simply write this data out to a new file in the endJob function. See
Code: Select all
script filter\output filename stats.fll