[any way] Export part of text file to another

Discussion in 'Mixed Languages' started by lysy.lbn, Feb 9, 2012.

  1. lysy.lbn

    lysy.lbn MDL Member

    Apr 20, 2011
    125
    65
    10
    Hi, I need script / program / code or whatever which can export part of log file (.ini) to another one

    Some Useless Thing
    Some Useless Thing
    direct="i need export this"
    Some Useless Thing
    Some Useless Thing

    Googled it several hours with no luck, hope some of you could help :confused:
    Any suggestion appreciated
     
  2. Calistoga

    Calistoga MDL Senior Member

    Jul 25, 2009
    420
    198
    10
    #2 Calistoga, Feb 9, 2012
    Last edited by a moderator: Apr 20, 2017
    Let me suggest using AutoIt.

    You'll use the IniRead function to accomplish this task.

    Code:
    Local $text = IniRead ( "filename", "section", "key", "default" )
    
    ; "default" is the value the function should return if your key doesn't exist
    
    MsgBox(0, "Value", $text) ; show a message box with the value
    
     
  3. lysy.lbn

    lysy.lbn MDL Member

    Apr 20, 2011
    125
    65
    10
    Unfortunetly I'm not good friend with auto it.. But thanks for your advice anyway :)

    Someone have other idea?
     
  4. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,106
    120
    You can work with C#?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,886
    20,283
    180
    #5 Alphawaves, Feb 10, 2012
    Last edited by a moderator: Apr 20, 2017
    Heres a simple example to retrieve certain string from file and write it to another in VB.NET:

    Code:
     ' Read lines in file: C:\log.ini
            Dim lines As String() = File.ReadAllLines("C:\log.ini")
            ' Get certain text (first line is not read, string on line 3 will be line 2)
            Dim read As String = lines(2)
            'Create log2.ini
            Using sw As New StreamWriter("C:\log2.ini")
                ' Write text you want to C:\log2.ini 
                sw.WriteLine(read.Substring(8, 18))
                sw.Close()
            End Using
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. lysy.lbn

    lysy.lbn MDL Member

    Apr 20, 2011
    125
    65
    10
    #6 lysy.lbn, Feb 13, 2012
    Last edited by a moderator: Apr 20, 2017
    (OP)
    I do not even know how to use it.. tried ask google but it's "black magic" for me.. But thanks for trying to helping me anyway :)
    I thought it could be possible using batch or some already exsiting app :(

    Well.. coming back to CTRL+C > CTRL+V :eek:
     
  7. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    he's is using vb.net all u would have to do is create a vb.net project copy and past the code and debug or compile to get your result. of coarse changing the code to point to the correct paths
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. searchengine

    searchengine Guest

    #8 searchengine, Apr 27, 2012
    Last edited by a moderator: Apr 20, 2017
    Name_Of.ini
    Code:
    Some Useless Thing
    Some Useless Thing
    direct="i need export this"
    Some Useless Thing
    Some Useless Thing
    Read_and_Export.cmd
    Code:
    @echo off
    
    for /f "tokens=1,2 delims==" %%a in (Name_Of.ini) do (
    if %%a==direct set direct=%%b
    )
    
    echo %direct% >export.ini