Home > Community > Forums > Custom IC SKILL > truncating a File

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 truncating a File 

Last post Tue, Oct 28 2008 12:25 PM by useratcad. 4 replies.
Started by useratcad 28 Oct 2008 01:17 AM. Topic has 4 replies and 1777 views
Page 1 of 1 (5 items)
Sort Posts:
  • Tue, Oct 28 2008 1:17 AM

    • useratcad
    • Not Ranked
    • Joined on Thu, Oct 16 2008
    • Posts 15
    • Points 195
    truncating a File Reply

    Hello,

     is there an easy way to truncate the beginning or the end of a file?

    I tought I can find a special position in file and then truncate the rest of it resp. cut everything above.

     

    Thanks Tim 

    • Post Points: 20
  • Tue, Oct 28 2008 4:12 AM

    • Bernd
    • Top 500 Contributor
    • Joined on Tue, Jul 15 2008
    • Unterhaching, Bavaria
    • Posts 26
    • Points 945
    Re: truncating a File Reply

    I'm not sure if can modify a file on the fly in SKILL,
    at least I never have done this.
    You can open a file read it's contents and copy the contents you
    want to a new file.

    Have a look at the

     - SKILL Language User Guide
      o I/O and File Handling
        * Working with File Offsets (fileTell, fileSeek)

    Bernd

    Just another lonesome cad guy
    • Post Points: 20
  • Tue, Oct 28 2008 6:51 AM

    • useratcad
    • Not Ranked
    • Joined on Thu, Oct 16 2008
    • Posts 15
    • Points 195
    Re: truncating a File Reply

    Thanks for the hint.

    I was poking around with fileTell &fileSeek, but it seemed too complicated to open a file then copy all the data until the 5th last line was reached. I can't even figure out, howto check if EOF is rechead within a while-loop or so.

    Maybe there is a better solution for my problem:

    I need to read and write some values into a config file like the windows ini-files:

    startdir=/etc/bin/

    mytext="hello world"

    oneNum=5 

    ...

     

    Thanks Tim 

    • Post Points: 20
  • Tue, Oct 28 2008 9:11 AM

    • Bernd
    • Top 500 Contributor
    • Joined on Tue, Jul 15 2008
    • Unterhaching, Bavaria
    • Posts 26
    • Points 945
    Re: truncating a File Reply

    Something like that?

     

    procedure( BFreadConfig( t_inFile "t" )
        let( ( l_keyValueList p_inPort t_key t_line t_value )
       
    p_inPort = infile( t_inFile )
       
    when( p_inPort
        while( gets( t_line p_inPort )
            when( t_line && t_line != "" && t_line != "\n"
            l_keyValueList = parseString( t_line "=" )
            t_key = car( l_keyValueList )
            t_value = cadr( l_keyValueList )
            printf( "Key: %s, Value: %s\n" t_key t_value )
            ) ;; close when
        ) ;; close while
    ) ;; close when      

    close( p_inPort )  

    ) ;; close let
    ) ;; cloes procedure


    procedure( BFmodifyConfig( t_outFile t_key t_value "ttt" )
        let( ( l_keyValueList p_inPort t_line p_outPort t_tmpFile )
       
    t_tmpFile = strcat( t_outFile ".tmp" )
    system( strcat( "cp " t_outFile " " t_tmpFile ) )
    p_inPort = infile( t_tmpFile )   
    p_outPort = outfile( t_outFile )
      
    when( p_inPort
        while( gets( t_line p_inPort )
            if( t_line && t_line != "" && t_line != "\n" then
            l_keyValueList = parseString( t_line "=" )
            car( l_keyValueList )
            if( t_key == car( l_keyValueList ) then
                fprintf( p_outPort "%s=%s\n" t_key t_value )
            else
                   fprintf( p_outPort t_line )
            ) ;; close if           
        else
                fprintf( p_outPort t_line )
            ) ;; close if
        ) ;; close while
    ) ;; close when      

    close( p_inPort )
    close( p_outPort )
    system( strcat( "rm -f " t_tmpFile ) ) 

    ) ;; close let
    ) ;; cloes procedure
     

    Just another lonesome cad guy
    • Post Points: 20
  • Tue, Oct 28 2008 12:25 PM

    • useratcad
    • Not Ranked
    • Joined on Thu, Oct 16 2008
    • Posts 15
    • Points 195
    Re: truncating a File Reply

    looks great!

     Thanks a lot, that helps definitly

    • Post Points: 5
Page 1 of 1 (5 items)
Sort Posts:
Started by useratcad at 28 Oct 2008 01:17 AM. Topic has 4 replies.