Sign in to follow this  
Followers 0
handro

Last post reguarding topic: Included full sourecode to receive help

3 posts in this topic

#1 ·  Posted (edited)

This program reads Database.txt, Copies main dir C:\TEST\Testpage\ to multiple different ones based on Split[1] and Split[3], So it created C:\TEST\Random1.1 , C:\TEST\Random2.2, Until 4.4

A file cap2.htm is found in C:\TEST\Testpage so it was copied to the Random.1-4 folders. The second loop reads file cap2.htm and goes to line 48 which contains "John Williams" , then replaces it with split[3] ( The information in the 3rd split which are 4 different names). Compile this program for your self, i included cap2.htm ..NOTE: FileWriteLine - Writes to the end of the file which is not what I need( I need to replace the text on line 48 that says John Williams with split[3], but when i MsgBox the output of $Worked it shows blank so there's also a problem with the way I programmed that, I cannot seem to fix this!!! Please help

Database.txt:

1,John Williams,random1.jpg

2,Wilma Flinstone,random2.jpg

3,Andrew SandShrew,random3.jpg

4,Goma Patroni,random4.jpg

$line=0
Do ; 
    $Line+=1
    $LineRead=FileReadLine("Database.txt",$Line)
    If $LineRead="" Then ExitLoop
    $Split=StringSplit($LineRead,",")
    $DirN=StringSplit($Split[3],".")
    DirCopy("C:\TEST\testpage\", "C:\TEST\"&$DirN[1]&"."&$Split[1])
Until $LineRead=""
$Line2=0
Sleep(1000)
Do
$Line2+=1
$LineRead2=FileReadLine("Database.txt",$Line2)
    If $LineRead2="" Then ExitLoop
$Split2=StringSplit($Lineread2,",")
$DirN2=StringSplit($Split2[3],".")
$File=FileOpen("C:\TEST\"&$DirN2&"."&$Split2[1]&"\cap2.htm",1)
$ToBeReplaced=FileReadLine("C:\TEST\"&$DirN2&"."&$Split2[1]&"\cap2.htm",48)
$Worked=StringReplace($ToBeReplaced,"John Williams",$Split[2])
MsgBox(0,"Worked:",$Worked)
FileWriteLine($File,$Worked)
Until $Lineread2=""
Edited by SmOke_N
Added code tags

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Your explanation of what you are trying to do is more confusing than your code itself, but you should comment your code on what you "think" its doing, because it looks like 1 big mess to me.

Also wrap it in Code tags so it looks easier to read.

Edit:

On the replace part... this is all you would need I'd think:

If $aSplit[0] > 1 Then ;Notice some error checking to make sure I don't GPF
    $sFileRead = FileRead($sFile)
    $sFileRead = StringReplace($sFileRead, "John Williams", $aSplit[2])
    FileClose(FileOpen($sFile, 2));Erase Previous content of file
    FileWrite($sFile, $sFileRead)
    MsgBox(64, "File Content", $sFileRead);Of course you'd remove this.
Else
    MsgBox(16, "Error", "Your code is about to blow up.")
EndIf
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

I have figured it out, I used _FileWriteToLine

made a new array for the name of the part of the line that was being replaced, it worked viola

took a lot of work :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0