I think this might be a bit more complicated then this appears.. because of the replacement of a line.. I was messing with other code.. but when the file resaved... it completely deleted the line, and consolidated the file. When I need the line to be empty.. after being deleted.
Basically its
1. Read file
2. Copy a specific Line in file. Which pastes to clipboard (Line 3 for instance. I might have to run the process twice to get my result I need, which is fine)
3. Paste that line to another file. (However there is already text here)
So would I have to delete the text and leave the line blank? First? Or would it just replace everything in that line on the second file?
File 1
Birds
Yoyo blanket keyboard <--- Copy this, line 2
Water
File 2
Computer
Screen harddrive hub <--- Copy and replace this with "Yoyo blanket keyboard"
Speakers
Etc
Any help would be greatly appreciated.
Stuff ive been playing with.. This deletes the line.. but consolidates the file.
Loop, Read, D:\Arcade\Emulators\epsxe\plugins\crypt_killer\nuvee_psx_guncon1.ini, D:\Arcade\Emulators\epsxe\plugins\crypt_killer\nuvee_psx_guncon1_.ini
If A_Index=10
Continue
else
FileAppend %A_LoopReadLine%`n
FileMove, D:\Arcade\Emulators\epsxe\plugins\crypt_killer\nuvee_psx_guncon1_.ini, D:\Arcade\Emulators\epsxe\plugins\crypt_killer\nuvee_psx_guncon1.ini, 1
return
Copy one line from one file, Completely replace Text on another specific line in another file
Re: Copy one line from one file, Completely replace Text on another specific line in another file
I see that there is a function called.
TF_InsertLine
Which was referenced years ago... I cant find any information on it though. So I guess maybe it was old function that isnt used anymore?
Also I think I should start it off like this..
Then after. I would like to paste %A_Index% into another text file. Maybe use the Fileappend function? However that file, at the specific line already has a text in it. Would I have to run something first to delete everything in that line leaving it empty? And then paste in the variable content above?
Any help would be appreciated. I can even send somebody a bit of paypal for the help.
Thank you
TF_InsertLine
Which was referenced years ago... I cant find any information on it though. So I guess maybe it was old function that isnt used anymore?
Also I think I should start it off like this..
Code: Select all
Loop
{
FileReadLine, 3, D:\Arcade\Tools\Demul Shooter\config.ini, %A_Index%
return
}
return
Any help would be appreciated. I can even send somebody a bit of paypal for the help.
Thank you
Re: Copy one line from one file, Completely replace Text on another specific line in another file
I think I can actually do this in parts.
Ill first delete the line I originally wanted replaced in the second file. Resave over the previous file.
Ill use the replace StringReplace to create the line that I want in the first file. Then save the file to a new file...
Then copy that entire line to ether a variable or the clipboard from the first file
Then use fileappend to copy it to the end of the second file.
(I believe since the file is an ini file.. the one that needs to be read... It doesnt matter where the line of text is located. (I could be wrong on that... but a simple test will confirm it.)
Im going to try and write the scripting for it now.
Ill first delete the line I originally wanted replaced in the second file. Resave over the previous file.
Ill use the replace StringReplace to create the line that I want in the first file. Then save the file to a new file...
Then copy that entire line to ether a variable or the clipboard from the first file
Then use fileappend to copy it to the end of the second file.
(I believe since the file is an ini file.. the one that needs to be read... It doesnt matter where the line of text is located. (I could be wrong on that... but a simple test will confirm it.)
Im going to try and write the scripting for it now.
- flyingDman
- Posts: 2817
- Joined: 29 Sep 2013, 19:01
Re: Copy one line from one file, Completely replace Text on another specific line in another file
try:
Code: Select all
sourceline := 2
targetline := 3
File1 = ; fileread, file1, %path2file1%
(
Birds
Yoyo blanket keyboard
Water
)
File2 = ; fileread, file2, %path2file2%
(
Computer
Screen harddrive hub
Speakers
)
tmp := strsplit(file1,"`n","`r")[sourceline]
for x,y in strsplit(file2,"`n","`r")
nFile2 .= (a_index = targetline ? tmp : y) "`n"
msgbox % nFile2 ; filedelete, %path2file2% ; fileappend, %file2%, %path2file2%
14.3 & 1.3.7
Re: Copy one line from one file, Completely replace Text on another specific line in another file
Code: Select all
sourceline := 3
targetline := 10
File1 =
(
Fileread, config.ini, D:\Arcade\Tools\Demul Shooter ; fileread, file1, %path2file1%
)
File2 =
(
Fileread, nuvee_psx_guncon1.ini, D:\Arcade\Emulators\epsxe\plugins\crypt_killer ; fileread, file2, %path2file2%
)
tmp := strsplit(file1,"`n","`r")[sourceline]
for x,y in strsplit(file2,"`n","`r")
nFile2 .= (a_index = targetline ? tmp : y) "`n"
msgbox % nFile2 ; filedelete, %path2file2% ; fileappend, %file2%, %path2file1%
FileDelete, %path2file2%
FileAppend, %file2%, D:\Arcade\Emulators\epsxe\plugins\crypt_killer
Thank you for taking the time to respond.
I think this isnt quite correct.. as it isnt working. But its close. Please take a look when you have a min.
Chris
- flyingDman
- Posts: 2817
- Joined: 29 Sep 2013, 19:01
Re: Copy one line from one file, Completely replace Text on another specific line in another file
My code is working alright (did you run the example?). The file1 = and file2 are simulating the result of fileread. See here: https://www.autohotkey.com/docs/commands/FileRead.htm
14.3 & 1.3.7
Re: Copy one line from one file, Completely replace Text on another specific line in another file
I mean what I posted isnt quite right as im unfamiliar with the format of the example. I think I got the last part wrong. I was looking for help wiht the corrections.
Ill continue to play with it.
Ill continue to play with it.
- flyingDman
- Posts: 2817
- Joined: 29 Sep 2013, 19:01
Re: Copy one line from one file, Completely replace Text on another specific line in another file
See if these explanations help: (please, practice with dummy files file1.ini and file2.ini in the script's folder)
Code: Select all
sourceline := 2
targetline := 3
fileread, file1, file1.ini ;reads the content of file1.ini into the variable file1
fileread, file2, file2.ini ;reads the content of file2.ini into the variable file2
tmp := strsplit(file1,"`n","`r")[sourceline] ;reads the second line of file1 into variable tmp
for x,y in strsplit(file2,"`n","`r") ;loops through each line of file2
nFile2 .= (x= targetline ? tmp : y) "`n" ;reconstructs file2 but when targetline is reached replaces the existing line with tmp
filedelete, file2.ini ;delete the old file2.ini
fileappend, %nfile2%, file2.ini ;creates a new file2.ini with the new content
14.3 & 1.3.7
Re: Copy one line from one file, Completely replace Text on another specific line in another file
I'm guessing you didn't Google for it, within the first 5 results, but you can find it here:
https://github.com/hi5/TF
I haven't looked at your questions/script but when dealing with INI in general you might be better off using AutoHotkey's INI related commands to read, write and delete entries.
Re: Copy one line from one file, Completely replace Text on another specific line in another file
Ill give this a shot today, been busy all weekend. And worked all night... off to sleep
Again thank you for the help
Again thank you for the help
Who is online
Users browsing this forum: Google [Bot], mikeyww and 284 guests