Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Apr 2004
    Posts
    47

    Creating multi files from 1 tab-delimited file

    Hey guys, long time no chat...

    I am kinda stuck on this one and looking for some guidance.

    I have a tab-delimited text file. I would like to take each line and
    output the data in that line to a new, separate html (php) file. So essentially, I am
    exporting a flatfile text database to html pages with each page being
    one formatted database record.

    I would like to load a text file as a template, then using the tab-delimited file, generate one file per row where each column contains the data from the file.

    The file would be saved as one of the data fields.

    For example:

    ITEM_NUM<TAB>TITLE<TAB>DESCRIPTION
    1<TAB>Title 1<TAB>Description 1
    2<TAB>Title 2<TAB>Description 2
    3<TAB>Title 3<TAB>Description 3

    Would generate 3 files.. a 1.php a 2.php and a 3.php each one containing:

    <html>
    <head>
    <title>$TITLE</title>
    <meta name="description" content="$DESCRIPTION" />
    ...etc

    I hope that makes sense. Any ideas, suggestions or samples?

    Thanks guys!
    - Hey Captain, we hooked up Data to the internet... Wanna see what he can do?

  2. #2
    Join Date
    Jun 2002
    Location
    Israel
    Posts
    1,843
    The way to go about that would be to use the TextFile.ReadToTable action, then for each element of the Table, use the String.Find String.Left, String.Mid and String.Right actions to separate each TAB separated parameter.
    Then insert each Data into place by replacing $TITLE and $DESCRIPTION and saving that string as a file.

    Hope that helped pointing you in the right direction.
    Good luck
    Yossi

  3. #3
    Join Date
    Apr 2004
    Posts
    47
    Thanks for the help yosik!

    I am well on my way and I have everything figured out... but I am still fighting with the String.Find String.Left, String.Mid and String.Right actions to break out the elements into variables so that I can write them out to the files correctly.

    I converted the file to comma delimited but I am still struggling. Could you please show me an example of the best way to break out these fields into variables from a text string?:

    sampleitem1,sam_item2,sample3,sam4,sample5,item6

    I can't belive that I am having such a difficult time with such a simple task. I know there has to be a simpler way than what I am trying to do but my mind is numb... I think I just need a KICK in the right direction.

    Thanks so much!
    - Hey Captain, we hooked up Data to the internet... Wanna see what he can do?

  4. #4
    Join Date
    Apr 2005
    Location
    São Paulo, Brazil
    Posts
    2,539
    There is a function shipped with AMS which you can use. Look for DelimitedStringFunctions.lua in the Gallery\Scripts subfolder of your AMS installation. With this function you will be able to split strings separated with TAB, comma, etc. immediately. Just copy and paste the code into your project...

    Ulrich

  5. #5
    Join Date
    Jun 2002
    Location
    Israel
    Posts
    1,843
    Right Ulrich. I forgot about this one, but that is exactly what StealthFD needs.
    Thanks for reminding us.

    Yossi

  6. #6
    Join Date
    Apr 2004
    Posts
    47
    I'll give that a try... Thanks guys!
    - Hey Captain, we hooked up Data to the internet... Wanna see what he can do?

  7. #7
    Join Date
    Apr 2004
    Posts
    47
    I can't belive that I am having so many problems with this...

    I can't even get the DelimitedStringFunctions.lua function and the sample script to work in a new project.

    Can someone else please try the DelimitedStringFunctions.lua function and the sample script and let me know that I'm not crazy... well, at least not about this.
    - Hey Captain, we hooked up Data to the internet... Wanna see what he can do?

  8. #8
    Join Date
    Apr 2005
    Location
    São Paulo, Brazil
    Posts
    2,539
    You aren't crazy, the example script won't work correctly as it is written, because the variable used in the sample ("string") is a reserved word in Lua.

    If you just rename the variable to something else, like TestString, and the script will work. Place the DelimitedStringToTable, TableToDelimitedString etc. functions in the Global Functions tab, and try this:
    Code:
    TestString = "Brett,Mark,Darryl,Lorne,Adam";
    tbResults = DelimitedStringToTable(TestString, ",");
    for i, name in tbResults do
        Dialog.Message("Name", name);
    end
    Ulrich

  9. #9
    Join Date
    Apr 2004
    Posts
    47
    OMG, can't belive I missed that.

    Thank you, you just confirmed that I am way overdue for a vacation!
    - Hey Captain, we hooked up Data to the internet... Wanna see what he can do?

  10. #10
    Join Date
    Apr 2004
    Posts
    47

    Post

    I just wanted to thank you guys for your help. I have completed the project and am just making it look pretty now.

    I couldn't get the DelimitedStringToTable function to work with the TAB delimiter... so I just resaved the file as comma delimited.

    Just for future reference, how do you set the DelimitedStringToTable delimiter to TAB or Char(9) ???

    I tried this with no luck:

    Code:
    tcharacter = String.Char(9);
    for a,b in items do
    TestString = b;
    tbResults = DelimitedStringToTable(TestString, tcharacter);
    end
    I'm working great - I am just curious. Thanks again! You guys are always great help!

    .
    - Hey Captain, we hooked up Data to the internet... Wanna see what he can do?

  11. #11
    Join Date
    Apr 2005
    Location
    São Paulo, Brazil
    Posts
    2,539
    Quote Originally Posted by StealthFD View Post
    Just for future reference, how do you set the DelimitedStringToTable delimiter to TAB or Char(9) ???
    To split fields separated by tabs, this is the easiest way:
    Code:
    tbResults = DelimitedStringToTable(TestString, "\t");
    Ulrich
    Last edited by Ulrich; 10-20-2008 at 10:27 PM.

  12. #12
    Join Date
    Apr 2004
    Posts
    47
    Thanks for the help!
    - Hey Captain, we hooked up Data to the internet... Wanna see what he can do?

Similar Threads

  1. New Version Available: 1.1.1017
    By Brett in forum MSI Factory 2.0 Discussion
    Replies: 4
    Last Post: 11-23-2007, 03:03 PM
  2. Reading Install Path From Registry
    By Staggan in forum Visual Patch 2.0
    Replies: 33
    Last Post: 05-04-2006, 10:31 AM
  3. HOWTO: Download and Install Files from the Web
    By Support in forum Setup Factory 6.0 Knowledge Base
    Replies: 0
    Last Post: 10-23-2002, 01:16 PM
  4. HOWTO: Install Files to the Windows Directory
    By Support in forum Setup Factory 6.0 Knowledge Base
    Replies: 0
    Last Post: 09-18-2002, 02:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts