I have a master file that return the equivalent of a string. MasterListing.txt
Exemple of that file:
ABC = B.2
DEF = B.5
HIJ = B.12
I also have multiple file:
File-1.txt
File-2.txt
File-3.txt
...
and so on but can be 1, 2, 10 or more files with same patern. There is only 1 value per file.
In those file there are value like:
ABC or DEF or HIJ and so on... many different codes
How could I create a new file with the same file patern as File-1.txt and so on but with the equivalent value from the MasterListing.txt? Only the equivalent value and not the ABC =
Thanks!
Match a file value with another file value Topic is solved
Re: Match a file value with another file value
I suggest that you attach one example of each of the three files, or provide the three specific examples.
Last edited by mikeyww on 19 Dec 2022, 20:45, edited 1 time in total.
Re: Match a file value with another file value
The Master List
File to match with the Master List
Expected result
Re: Match a file value with another file value
Code: Select all
dir = %A_ScriptDir%
masterFile = %dir%\MasterListing.txt
m := {}
FileRead, master, %masterFile%
For each, line in StrSplit(master, "`n", "`r")
part := StrSplit(line, "="), m[Trim(part.1)] := Trim(part.2)
FileRead, text, %dir%\File-1.txt
FileAppend, % m[text], %dir%\Result-1.txt
MsgBox, 64, Done, Done!
Code: Select all
dir = %A_ScriptDir%
masterFile = %dir%\MasterListing.txt
ini = %dir%\MasterListing.ini
FileRead, master, %masterFile%
FileRecycle, %ini%
FileAppend, [Main]`n%master%, %ini%
FileRead, text, %dir%\File-1.txt
IniRead, text2, %ini%, Main, %text%
FileRecycle %dir%\Result-1.txt
FileAppend, %text2%, %dir%\Result-1.txt
Run, %dir%\Result-1.txt
Re: Match a file value with another file value
Great Thank! It works as expected but for the first code when the value from File-1.txt is like "1ABC" or contains other characters like a "-ABC" it does not work
Re: Match a file value with another file value Topic is solved
You haven't said anything about that, or provided any rules or examples for it.
Code: Select all
dir = %A_ScriptDir%
masterFile = %dir%\MasterListing.txt
file = %dir%\File-1.txt
out = %dir%\Result-1.txt
m := {}
FileRead, master, %masterFile%
For each, line in StrSplit(master, "`n", "`r")
part := StrSplit(line, "="), m[Trim(part.1)] := Trim(part.2)
FileRead, text, %file%
FileRecycle, %out%
For k, v in m
text := StrReplace(text, k, v)
FileAppend, %text%, %out%
Run, %out%
Re: Match a file value with another file value
Perfect
Thanks!
Thanks!
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], peter_ahk and 162 guests