sfunk1x Posted December 16, 2005 Share Posted December 16, 2005 I need to modify the index.htm of a website. Only problem is, there was 7 subfolders off root, and there are 100 subfolders in each of the 7 subfolders, and there are (you guessed it) 32 subfolders in each of those 100 subfolders. In EACH of those folders, the index.htm needs to have one string replaced. The string is a JRE version check that forces the client to either use java or just use ie without javascript. I want to modify the file so the user is not forced to use java (whcih means a seperate download and install for the end user). What I can't figure out, however, is to how to make this perform a recursive search and modify the file in each fo the subfolders off the root of the website. Can anyone spend some time tonight and assist me on this? I'd really appreciate it, and I'd buy you virtual beer for your help! :-) So, this is my code so far: $search = FileFindFirstFile("index.htm") If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop StringReplace("if (ver == 4)", "", "if (ver >= 4)") WEnd ; Close the search handle FileClose($search) Link to comment Share on other sites More sharing options...
randallc Posted December 16, 2005 Share Posted December 16, 2005 (edited) Hi,this recursive request is so frequent, I may make a list here and link to it!http://www.autoitscript.com/fileman/users/jdeb/jdeb_autoit_stuff.htmDirFrench1.au3Dir command like dos ?, need to store dir names in a file OptionsLarry's recursive filesearch UDF?Autoit3Explorer.au3ExploreAU3cameronsdadUDF: _FileGetTreeList, _FileFindAllR, recursively list folders and files Options RatingUDF: Recursive directory size, output to XML Options RatingBlindWig rewrote the _FileGetTreeList() function.BlindWig'sDeleting old files Options LxPDOSAlex [DPS -cf my DOS coms link]I'm sure there are others; Maybe others can contribute to the list of recursive directory scripts which could be modified for this sort of purpose?Best, RandallPS I'll duplicate this so all keywords find it from a abase post... Edited December 16, 2005 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
randallc Posted December 16, 2005 Share Posted December 16, 2005 Added today;BlindWig rewrote the _FileGetTreeList() function.[]not by me!Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
seandisanti Posted December 16, 2005 Share Posted December 16, 2005 I need to modify the index.htm of a website. Only problem is, there was 7 subfolders off root, and there are 100 subfolders in each of the 7 subfolders, and there are (you guessed it) 32 subfolders in each of those 100 subfolders. In EACH of those folders, the index.htm needs to have one string replaced. The string is a JRE version check that forces the client to either use java or just use ie without javascript. I want to modify the file so the user is not forced to use java (whcih means a seperate download and install for the end user). What I can't figure out, however, is to how to make this perform a recursive search and modify the file in each fo the subfolders off the root of the website. Can anyone spend some time tonight and assist me on this? I'd really appreciate it, and I'd buy you virtual beer for your help! :-) So, this is my code so far: $search = FileFindFirstFile("index.htm") If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop StringReplace("if (ver == 4)", "", "if (ver >= 4)") WEnd ; Close the search handle FileClose($search)try this... currently the starting directory is the root of c: (leave backslash off when you change path because it's added in other places in the code), files changed are first backed up with .old extension. untested $tosearch = "C:" $output = FileOpen("c:\filelist.txt",2) $start = TimerInit() RecFileSearch($tosearch) FileClose($output) MsgBox(0,"done","it only took " & int(TimerDiff($start)/1000) & " seconds") Func RecFileSearch($current) Local $search = FileFindFirstFile($current & "\*.*") While 1 Dim $file = FileFindNextFile($search) If @error Or StringLen($file)<1 Then ExitLoop If $file = "index.html" Then Fixit($current & "\" & $file) If StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) Then RecFileSearch($current & "\" & $file) WEnd FileClose($search) EndFunc Func Fixit($thefile) $content = FileRead($thefile,FileGetSize($thefile)) StringReplace($content,"if (ver == 4)","if (ver >= 4)") FileMove($thefile,StringLeft($thefile,StringLen($thefile)-3) & "old") FileWrite($thefile,$content) EndFunc Link to comment Share on other sites More sharing options...
Locodarwin Posted December 16, 2005 Share Posted December 16, 2005 Here's a version of what you're asking for using Larry's UDF, with some cheating and brute-forceness (i.e. no error checking). Compile it and place it in the root of the tree to be searched. ; sfunkx1 Search & Replace utility #include <larryUDF.au3>;or whatever you've named it. Dim $search[30000];assume a large number of files could be found $search = _FileSearch("index.html",1) If $search[0] = 0 Then Exit For $i = 1 to $search[0] Run("notepad.exe " & $search[$i], "", @SW_HIDE) WinWaitActive("index.html - Notepad") Send("^h") WinWaitActive("Replace") Send("if (ver == 4){TAB}") Send("if (ver >= 4){TAB 4}") Send("{ENTER}") WinActivate("index.html - Notepad") Send("^s") Send("!f") Send("x") Next Exit Yeah, I used Send(), which is cheating - but if it works, use it! (Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent] Link to comment Share on other sites More sharing options...
seandisanti Posted December 16, 2005 Share Posted December 16, 2005 Here's a version of what you're asking for using Larry's UDF, with some cheating and brute-forceness (i.e. no error checking). Compile it and place it in the root of the tree to be searched. ; sfunkx1 Search & Replace utility #include <larryUDF.au3>;or whatever you've named it. Dim $search[30000];assume a large number of files could be found $search = _FileSearch("index.html",1) If $search[0] = 0 Then Exit For $i = 1 to $search[0] Run("notepad.exe " & $search[$i], "", @SW_HIDE) WinWaitActive("index.html - Notepad") Send("^h") WinWaitActive("Replace") Send("if (ver == 4){TAB}") Send("if (ver >= 4){TAB 4}") Send("{ENTER}") WinActivate("index.html - Notepad") Send("^s") Send("!f") Send("x") Next Exit Yeah, I used Send(), which is cheating - but if it works, use it!Welcome to the forum! Link to comment Share on other sites More sharing options...
Locodarwin Posted December 16, 2005 Share Posted December 16, 2005 Welcome to the forum!Thanks!By the way, sfunk1x, I put in a search filename of index.html, so you'll want to chop off the "L" if you decide to use my version for your project. (Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent] 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