Announcement

Collapse
No announcement yet.

Extract string from file and store it

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

  • Extract string from file and store it

    How can we extract the string path here at the bottom of the opt file as you can see in the image without the double quotes and store it in a text file or just store it in a variable.
    I figure this can be done writing a lua script or using the string variables. But this is above my pay grade and so i ask for help.

    From another topic i did manage to get this path using a vsscript a friend wrote. But i prefer to see other options as i hope lua coding will be easier.

    Thanks...







  • #2
    Please zip the usercfg.opt file and attach the archive here.

    Ulrich

    Comment


    • #3
      i attached the UserCFG file.
      Attached Files

      Comment


      • #4
        Try this code:
        Code:
        function GetInstalledPackagesPath(sInputFile)
           -- the opt file is Unix formatted, i.e. does not end its lines with \r\n
           -- due to this, TextFile.ReadToTable() does not work without further changes
           local sOpt = TextFile.ReadToString(sInputFile);
           local sFound = string.match(sOpt, ".*InstalledPackagesPath[ \"]*([^\"%c]*).*");
           -- this will return the path without quotes, or nil if not found
           return(sFound);
        end
        
        -- use proper path to file, this line is for testing only
        local sPathToOptFile = _SourceFolder .. "\\UserCfg.opt";
        
        -- extract the desired path from config file
        local sPathToPackages = GetInstalledPackagesPath(sPathToOptFile);
        
        -- show result
        if (sPathToPackages ~= nil) then
           Dialog.Message("", "Path to installed packages:\r\n" .. sPathToPackages, MB_OK, MB_ICONINFORMATION);
        else
           Dialog.Message("", "Something went wrong!", MB_OK, MB_ICONEXCLAMATION);
        end
        Ulrich

        Comment


        • #5
          Thanks Ulrich as it works perfect.

          Comment

          Working...
          X