angelong9 Posted September 19, 2009 Share Posted September 19, 2009 Hi guys, I'm a complete newb to AutoIt but there is a tedious thing I want to do with netload.in that only AutoIt could make it easier for me. For netload.in links, usually the links are like: 1) http://www.netload.in/dateistySAD12345/hello.rar.htm But if you go to the link, it'll actually go to 2) http://www.netload.in/dateistySAD12345.htm Links are not real btw So what I want the script to do is open a text file with netload links in it(location given by me of course), replace the 1st slash from the right and whatever's behind it with ".htm", THEN replace another string of "http://www." with "http://LOGIN:PASSWORD@", and finally saves and overwrite the same file. I know this is a lot to ask but I really need this! I don't even know where to start. Please help me with this and I'm sure I can learn something from this Thank you very much! Link to comment Share on other sites More sharing options...
dantay9 Posted September 19, 2009 Share Posted September 19, 2009 (edited) Welcome to the forum! You are looking for string functions. There are many to choose from. Look in the help file for all the functions that deal with strings. $String = "http://www.netload.in/dateistySAD12345/hello.rar.htm" $String = StringLeft($String, StringInStr($String, "/", 0, -1) - 1) $String = StringReplace($String, "http://www.", "http://LOGIN:PASSWORD@") Just so you can learn a little bit more about Autot, try looking up how to write this string to a file. Look up FileWrite(), FileRead(), FileReadLine(), FileOpen(), and FileClose() in the help file. If you need help, come back with what you tried and we will be glad to help. Edited September 19, 2009 by dantay9 Link to comment Share on other sites More sharing options...
angelong9 Posted September 19, 2009 Author Share Posted September 19, 2009 (edited) Thank you! Well, I tried it out and read some posts and tried writing something on my own.. It ALMOST worked.. Just one little problem... Please help me Here is my code: $TextFileName = "Netload.txt" $String = "http://www." $String2 = "http://LOGIN:PASSWORD@" $FileContents = FileRead($TextFileName) $n = StringInStr($FileContents,"/", 0, -1) $mid = StringLeft($FileContents, $n-1) $Replace = $mid & ".htm" $FileContents = StringReplace($FileContents,$mid,$Replace) $FileContents = StringReplace($FileContents, $String, $String2) FileDelete($TextFileName) FileWrite($TextFileName,$FileContents) Well $String2 replaces $String just fine, but for the replacing the forward slash and characters after it part, instead of http://www.netload.in/dateistySAD12345/hello.rar.htm to http://LOGIN:PASSWORD@netload.in/dateistySAD12345.htm It became like this: http://www.netload.in/dateistySAD12345/hello.rar.htm to http://LOGIN:PASSWORD@netload.in/dateistySAD12345.htm/hello.rar.htm Please help me fix my code.. Thank you very much! Edited September 19, 2009 by angelong9 Link to comment Share on other sites More sharing options...
angelong9 Posted September 19, 2009 Author Share Posted September 19, 2009 Somebody help me please? Thank you! Link to comment Share on other sites More sharing options...
dantay9 Posted September 19, 2009 Share Posted September 19, 2009 Sorry about the wait. I had a soccer game to go to. I think this is what you are trying to do. What you were doing is replacing the text. That was all fine. The only thing you didn't do was delete the string to the right of the slash mark. Here is the easiest way to do it. $TextFileName = "Netload.txt" $FileContents = FileRead($TextFileName) $FileContents = StringReplace($FileContents, "http://www.", "http://LOGIN:PASSWORD@") $n = StringInStr($FileContents, "/", 0, -1) $FileContents = StringLeft($FileContents, $n - 1) $FileContents &= ".htm" ;same as $String = $String & ".htm" FileDelete($TextFileName) FileWrite("t" & $TextFileName, $FileContents) Link to comment Share on other sites More sharing options...
angelong9 Posted September 19, 2009 Author Share Posted September 19, 2009 Ah, yes, it works now.. I didn't know how to delete the parts after the slash, now I do! Thank you again! Rep+ Link to comment Share on other sites More sharing options...
dantay9 Posted September 19, 2009 Share Posted September 19, 2009 Your welcome. Just for learning purposes, I didn't actually delete the string on the end. All I did was just take the left side of the string. To delete a number of characters from the beginning or the end of a string, use StringTrimLeft() or StringTrimRight(). If you are trying to replace text in the middle, you can use StringReplace($String, "string to find", ""). That will effectively delete the text in the middle. Link to comment Share on other sites More sharing options...
angelong9 Posted September 20, 2009 Author Share Posted September 20, 2009 Ah, another problem! How come this script doesn't work for .txt file with multilines of links? It only replaces the last link.. Could you tell me how to loop it if thats what im missing? Thanks! Link to comment Share on other sites More sharing options...
dantay9 Posted September 20, 2009 Share Posted September 20, 2009 Your best bet would be to use FileReadLine() to separate the lines into single URLs. Then you just have to loop that until you get to the last line. Then write the file outside the loop. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now