Inserting file name into the file

Get help with installation and running here.

Moderators: DataMystic Support, Moderators

DavidHill

Inserting file name into the file

Postby DavidHill » Sat Jan 22, 2005 8:12 am

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

User avatar
DataMystic Support
Site Admin
Posts: 2154
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Postby DataMystic Support » Mon Jan 24, 2005 11:13 am

Use an Add Header/Footer/Left or Right Margin filter, with text of

@inputFilename

and/or see the right-click menus to add other macros.
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

Moz
Posts: 11
Joined: Sun Oct 09, 2005 8:15 pm

Postby Moz » Thu Mar 16, 2006 3:19 am

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

User avatar
DataMystic Support
Site Admin
Posts: 2154
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Postby DataMystic Support » Thu Mar 16, 2006 7:52 am

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.
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

Moz
Posts: 11
Joined: Sun Oct 09, 2005 8:15 pm

Postby Moz » Fri Mar 17, 2006 10:31 pm

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.


Hi Simon,

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

User avatar
DataMystic Support
Site Admin
Posts: 2154
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Postby DataMystic Support » Mon Mar 20, 2006 7:58 am

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

Code: Select all

script filter\output filename stats.fll

for an example.
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments


Return to “TextPipe Tips and Tricks, Questions and Support”

Who is online

Users browsing this forum: No registered users and 2 guests