styles3000 Posted December 4, 2009 Posted December 4, 2009 Is there a way to write this code below without so much repitition? expandcollapse popup$Title = _GetTitle("D:\Documents and Settings\Taevon Jones\Desktop\Extracted Keywords\0001.txt") ;MsgBox(0,'',$Title) sleep(3000) FileMove("D:\Documents and Settings\Taevon Jones\My Documents\One a be HyperVRE Webpages\christmas greetings\index1.htm", "D:\Documents and Settings\Taevon Jones\My Documents\One a be HyperVRE Webpages\christmas greetings\"&$title&".htm",1) sleep(3000) $Title = _GetTitle("D:\Documents and Settings\Taevon Jones\Desktop\Extracted Keywords\0002.txt") ;MsgBox(0,'',$Title) sleep(3000) FileMove("D:\Documents and Settings\Taevon Jones\My Documents\One a be HyperVRE Webpages\christmas greetings\index2.htm", "D:\Documents and Settings\Taevon Jones\My Documents\One a be HyperVRE Webpages\christmas greetings\"&$title&".htm",1) sleep(3000) $Title = _GetTitle("D:\Documents and Settings\Taevon Jones\Desktop\Extracted Keywords\0003.txt") ;MsgBox(0,'',$Title) sleep(3000) FileMove("D:\Documents and Settings\Taevon Jones\My Documents\One a be HyperVRE Webpages\christmas greetings\index3.htm", "D:\Documents and Settings\Taevon Jones\My Documents\One a be HyperVRE Webpages\christmas greetings\"&$title&".htm",1) sleep(3000) Func _GetTitle($File) $text = FileRead($File) $posStart = StringInStr($text,'<title>') $posEnd = StringInStr($text,'</title>') If $posStart = 0 or $posEnd = 0 Then MsgBox(0,'ERROR','This File doesnt Contain a Title') $result = '' ; This File doesnt Contain a Title Else $result = StringMid($text,$posStart+7,$posEnd-($posStart+7)) EndIf $result= StringLower($result) Return $result EndFunc Func _SendTitle($Title) Sleep(250) ControlSend("Notepad",'','', String($Title)) ControlSend('[Class:Notepad]', '', 'Edit1', $Title) Sleep(250) EndFunc
bo8ster Posted December 4, 2009 Posted December 4, 2009 First step I would do is have variables for your paths. 'D:\Documents and Settings\Taevon Jones\My Documents\One a be HyperVRE Webpages' is used a lot. A step further would be to put a counter in a loop so it will be like _FileMove(path & i & rest of path, other path & i & rest of other path) where i is your counter. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]
stampy Posted December 4, 2009 Posted December 4, 2009 While I'm presuming that the 0001 would go beyond and this code wouldn't work, this sample for loop should give you an idea of how the repetition can be used in a loop. For $i = 1 to 3 $Title = _GetTitle("D:\Documents and Settings\Taevon Jones\Desktop\Extracted Keywords\000"&$i&".txt") ;MsgBox(0,'',$Title) sleep(3000) FileMove("D:\Documents and Settings\Taevon Jones\My Documents\One a be HyperVRE Webpages\christmas greetings\index"&$i&".htm", "D:\Documents and Settings\Taevon Jones\My Documents\One a be HyperVRE Webpages\christmas greetings\"&$title&".htm",1) sleep(3000) Next Func _GetTitle($File) $text = FileRead($File) $posStart = StringInStr($text,'<title>') $posEnd = StringInStr($text,'</title>') If $posStart = 0 or $posEnd = 0 Then MsgBox(0,'ERROR','This File doesnt Contain a Title') $result = '' ; This File doesnt Contain a Title Else $result = StringMid($text,$posStart+7,$posEnd-($posStart+7)) EndIf $result= StringLower($result) Return $result EndFunc Func _SendTitle($Title) Sleep(250) ControlSend("Notepad",'','', String($Title)) ControlSend('[Class:Notepad]', '', 'Edit1', $Title) Sleep(250) EndFunc
styles3000 Posted December 5, 2009 Author Posted December 5, 2009 Thank you code master Stampy and Bo8ster. Your help is greatly appreciated.While I'm presuming that the 0001 would go beyond and this code wouldn't work, this sample for loop should give you an idea of how the repetition can be used in a loop.For $i = 1 to 3 $Title = _GetTitle("D:\Documents and Settings\Taevon Jones\Desktop\Extracted Keywords\000"&$i&".txt") ;MsgBox(0,'',$Title) sleep(3000) FileMove("D:\Documents and Settings\Taevon Jones\My Documents\One a be HyperVRE Webpages\christmas greetings\index"&$i&".htm", "D:\Documents and Settings\Taevon Jones\My Documents\One a be HyperVRE Webpages\christmas greetings\"&$title&".htm",1) sleep(3000) Next Func _GetTitle($File) $text = FileRead($File) $posStart = StringInStr($text,'<title>') $posEnd = StringInStr($text,'</title>') If $posStart = 0 or $posEnd = 0 Then MsgBox(0,'ERROR','This File doesnt Contain a Title') $result = '' ; This File doesnt Contain a Title Else $result = StringMid($text,$posStart+7,$posEnd-($posStart+7)) EndIf $result= StringLower($result) Return $result EndFunc Func _SendTitle($Title) Sleep(250) ControlSend("Notepad",'','', String($Title)) ControlSend('[Class:Notepad]', '', 'Edit1', $Title) Sleep(250) EndFunc
styles3000 Posted December 5, 2009 Author Posted December 5, 2009 Thank you code master Stampy and Bo8ster. Your help is greatly appreciated.Code Master Stampy, The code runs fine with the exception of 0002.txt, and 0010 thru 0020. For some strange reason, the script ignores 0002.txt. I even isolated 0002.txt and ran it by itselfs ....and it still would'nt FileMove the string. When AutoIT gets to 0010.txt thru 0020.txt, it says ERROR no title when in fact it does have a title string within it to be extracted.(I opened it up and did a manual examination). What can a brotha do in this situation?
bo8ster Posted December 6, 2009 Posted December 6, 2009 (edited) Use ConsoleWrite to print out what is being passed to File Move. I suspect that you need to add additional single quotes as the file name has spaces. Think of passing that string to a dos window as a path, its not going to be able to handle it. example ' "path' " Edit: Added spaces for clarity - remove the spaces when using the path example. Edited December 6, 2009 by bo8ster Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]
styles3000 Posted December 10, 2009 Author Posted December 10, 2009 I'm not to sure on how to use ConsoleWrite.....Could ya guide me a little?FileMove("D:\Documents and Settings\Taevon Jones\My Documents\One a be HyperVRE Webpages\christmas greetings\index2.htm", "D:\Documents and Settings\Taevon Jones\My Documents\One a be HyperVRE Webpages\christmas greetings\"&$title&".htm",1)ConsoleWrite("&$title&".htm")
styles3000 Posted December 11, 2009 Author Posted December 11, 2009 I've just been given this script, but its not exactly doing what I thought it was going to do, ...... expandcollapse popup#Include <Array.au3> $sKeywordsDir = "D:\Documents and Settings\Taevon Jones\Desktop\Extracted Keywords\" $sIndexDir = "D:\Documents and Settings\Taevon Jones\My Documents\One a be HyperVRE Webpages\christmas greetings\" $sTitleDir = "D:\Documents and Settings\Taevon Jones\My Documents\One a be HyperVRE Webpages\christmas greetings\" ;$sKeywordsDir = "C:\Temp\Extracted Keywords\" ;$sIndexDir = "C:\Temp\New Folder\" ;$sTitleDir = "C:\Temp\New Folder\" $search = FileFindFirstFile($sKeywordsDir&"*.*") Dim $FileCount[999] $FileCount[0] = '0' While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $FileCount[0] = $FileCount[0]+1 $FileCount[$FileCount[0]] = $file WEnd FileClose($search) _ArrayDisplay($FileCount) For $i = 1 to $FileCount[0] $Title = _GetTitle($sKeywordsDir&$FileCount[$i]) sleep(250) MsgBox(0,$i,$sIndexDir&$FileCount[$i]&@CRLF&$sIndexDir&$title&".htm") $Title = StringReplace($Title,'"',"'") $Title = StringReplace($Title,'?','') FileMove($sIndexDir&$FileCount[$i], $sTitleDir&String($title)&".htm",1) Next Func _GetTitle($File) $text = FileRead($File) $posStart = StringInStr($text,'<title>') $posEnd = StringInStr($text,'</title>') If $posStart = 0 or $posEnd = 0 Then MsgBox(0,'ERROR','This File doesnt Contain a Title') $result = '' ; This File doesnt Contain a Title Else $result = StringMid($text,$posStart+7,$posEnd-($posStart+7)) EndIf $result= StringLower($result) Return $result EndFunc Func _SendTitle($Title) Sleep(250) ControlSend("Notepad",'','', String($Title)) ControlSend('[Class:Notepad]', '', 'Edit1', $Title) Sleep(250) EndFunc Its not changing the .htm files like I want like in the script below. With the script below ,I can execute it and I can see the script go to work and the index.htm files changing to what each .txt file is . What could be the problem? expandcollapse popup$sKeywordsDir = "D:\Documents and Settings\Taevon Jones\Desktop\Extracted Keywords\" $sIndexDir = "D:\Documents and Settings\Taevon Jones\My Documents\One a be HyperVRE Webpages\christmas greetings\" $sTitleDir = "D:\Documents and Settings\Taevon Jones\My Documents\One a be HyperVRE Webpages\christmas greetings\" $search = FileFindFirstFile($sKeywordsDir&"*.*") $FileCount = '1' While 1 $file = FileFindNextFile($search) If @error Then ExitLoop ;MsgBox(4096, "File:", $file) $Title = _GetTitle($sKeywordsDir&$file) ;MsgBox(0,'',$Title) sleep(3000) FileMove($sIndexDir&"index"&$FileCount&".htm", $sTitleDir&$title&".htm",1) sleep(5000) $FileCount = $FileCount+1 WEnd FileClose($search) Func _GetTitle($File) $text = FileRead($File) $posStart = StringInStr($text,'<title>') $posEnd = StringInStr($text,'</title>') If $posStart = 0 or $posEnd = 0 Then MsgBox(0,'ERROR','This File doesnt Contain a Title') $result = '' ; This File doesnt Contain a Title Else $result = StringMid($text,$posStart+7,$posEnd-($posStart+7)) EndIf $result= StringLower($result) Return $result EndFunc Func _SendTitle($Title) Sleep(250) ControlSend("Notepad",'','', String($Title)) ControlSend('[Class:Notepad]', '', 'Edit1', $Title) Sleep(250) EndFunc
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