How to make an app - Andromo App Maker

Announcement

Collapse
No announcement yet.

Read each folder's ini file and compile the values in one txt.

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

  • Read each folder's ini file and compile the values in one txt.

    I'm missing something here... I'm trying to go over a mountain when I know there is a easier way around it...

    Objective:
    Get a list of subfolders
    Read a specific value that resides in each subfolder's ini file
    Write the subfolder's name and the specific value of that ini file to a text/csv file in the parent folder 'C:\Folder\newtext.csv'
    Text File Example:
    Subfolder1, inivalue1, inivalue2
    Subfolder2, inivalue1, inivalue2

    Enviroment:
    Parent Folder: C:\Folder
    Subfolders: C:\Folder\Subfolder1 C:\Folder\Subfolder2.. etc
    Each Subfolder has a "info.ini"


    My Attempt:
    Currently, I have downloaded Ulrich's example here
    Which does not really help me too much... Where do I look for information on how to complete this task. I know it's something to do with tables but unsure...

    I've actually searched this forum for something similar and the above mentioned in the only thing relatively close to what I'm trying to achieve. Any help on this will be appreciated.


    I could just hard code the list of folders myself into the app and just release a newer version when there is a need for a new subfolder but this isn't the way I would want to go.



  • #2
    Hi gt4jk
    I have done a sample for you - when you run it it creates your folders on C; drive , it also copies info.ini files to 3 SubFolders
    It scans the folders and adds to listbox When you select an ini file it gives you the path, then click on populate button to see ini file sections in the other listbox
    It also dispays the value in a paragraph, selecting another ini file and clicking populate does the same and appends to a temp file
    the Save button you can view contents or save to C;\Folder [Note the file is overwritten] on each save
    I hope this will help you
    ListBox-INIFile.apz

    Comment


    • #3
      With respect for Charlie's fine example, you might find this a little easier to follow:

      Nb.
      For the sake of somplicity, this example is not coded to check for errors, so the following 3 conditions must be met first.
      • the parent folder resides on the System Drive
      • the parent folder is named "Folder"
      • the INI files reside within the parent folder's subFolders (and contain valid data
      Code:
      -- Establish which drive is the System Drive
      local tPath = String.SplitPath(_WindowsFolder);
      local sysDrive = tPath.Drive;
      
      -- Get a list of subFolders in the folder named "Folder" ...
      local tFolderPaths = Folder.Find(sysDrive.."\\Folder", "*", false, nil);
      if tFolderPaths then
          for k,v in pairs (tFolderPaths) do
              local tPathParts = String.SplitPath(v);
              local subFolder =  tPathParts.Filename;
              
              -- and write the names of the subFolders to the CSV file in the parent folder
              TextFile.WriteFromString(sysDrive.."\\Folder\\newtext.csv", subFolder..": ", true);            
      
              -- Establish the filePath to the INI files
              local tFiles = File.Find(v, "*ini", false, false, nil, nil);
              if tFiles then
                  for k,v in pairs (tFiles) do
                      local sFilePath = Table.Concat(tFiles, ";", 1, -1);
                      
                      -- Read the values from each subFolder's INI file ...
                      local tValueNames = INIFile.GetValueNames(sFilePath, "Section");
                      for k,v in pairs (tValueNames) do
                          local sValue = INIFile.GetValue(sFilePath, "Section", v);
                      
                          -- and write those values to the CSV file
                          TextFile.WriteFromString(sysDrive.."\\Folder\\newtext.csv", sValue .. " ", true);
                      end
                      -- while ensuring that values from each INI file are seperated by a new line
                      TextFile.WriteFromString(sysDrive.."\\Folder\\newtext.csv", "\r\n", true);
                  end
              end
          end
      end

      Comment


      • #4
        Edit:
        It also assumes a 4th condition is met:
        - that the value assigned to the Section Name of the INI files is: "Section".

        Comment

        Working...
        X