Announcement

Collapse
No announcement yet.

Extract part of a text file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Stanislaw
    replied
    WOW, I think I just guessed it...

    mytable = TextFile.ReadToTable("%usercfg%");
    -- read the file into a string
    local sConfig = TextFile.ReadToString(SessionVar.Expand("%usercfg% "));
    -- find what matters
    local sPath = string.match(sConfig, ".*InstalledPackagesPath "(.*)".*");
    MYpath = tostring(sPath)

    Leave a comment:


  • Stanislaw
    replied
    Sort of, but sometimes it works and sometimes it doesn't.
    I am not sure if perhaps I need to use the tostring command somehow...

    Leave a comment:


  • Ulrich
    replied
    Sorry, I was away. Do you have a solution?

    Ulrich

    Leave a comment:


  • Stanislaw
    replied
    Disregard. Too much work and too little coffee...

    Leave a comment:


  • Stanislaw
    replied
    OK, I am probably a total idiot. :-/

    So how do I double the "" in the string for the correct path?

    Leave a comment:


  • Stanislaw
    replied
    I am shocked.

    You are my hero.

    LOL

    Leave a comment:


  • Ulrich
    replied
    Try this:

    Code:
    -- read the file into a string
    local sConfig = TextFile.ReadToString(SessionVar.Expand("%SourceFolder%\\config.opt"));
    -- find what matters
    local sPath = string.match(sConfig, ".*InstalledPackagesPath \"(.*)\".*");
    -- present the result
    Dialog.Message("", sPath);
    Ulrich

    Leave a comment:


  • Stanislaw
    replied
    Thanks.
    This is not really a json file apparently... The very line is simple text, without any brackets etc. Last line:

    (...)long list(...)
    {SSSSS
    Enabled 1
    Quality 2
    }
    {AA
    Enabled 1
    Type 2
    Quality 2
    }
    {Bloom
    Enabled 1
    Quality 2
    }
    {DOF
    Enabled 1
    Quality 2
    }
    {Buildings
    Enabled 1
    Quality 2
    }
    {VegetationLarge
    Enabled 1
    Quality 2
    }
    {VegetationSmall
    Enabled 1
    Quality 2
    }
    {TextureSynthesis
    Quality 2
    }
    {PostProcess
    Enabled 1
    EyeAdaptation 1
    ColorGrading 1
    Sharpen 1
    Fringe 1
    LensDistortion 0
    Dirt 1
    LensFlare 1
    FilmGrain 1
    Vignette 1
    LensBlurMultiplier 1.000000
    FringeMultiplier 1.000000
    }
    {VectorDataTessellation
    Enabled 1
    Quality 2
    }
    }
    InstalledPackagesPath "C:\Path"

    Leave a comment:


  • Ulrich
    replied
    My preferred approach is using dkjson for reading JSON files in Lua.
    https://forums.indigorose.com/forum/...from-json-file

    Ulrich

    Leave a comment:


  • Stanislaw
    replied
    --Read the file to table (the file referenced in the variable):
    mytable = TextFile.ReadToTable("%usercfg%");

    Basically I need to find the line which contains InstalledPackagesPath: and extract from that line information located between quotation marks.

    Leave a comment:


  • Stanislaw
    started a topic Extract part of a text file

    Extract part of a text file

    Hi.
    I've got a text file (actually it is more like a json file, with the .opt extension). Anyway, somewhere in this file there is a plain-text line:

    InstalledPackagesPath "Specific_Path"

    Basically I need to open it, search thru it to find that line (it occurs just once) and create a variable from what is written in quotation marks. I would appreciate some help
Working...
X