(* USE WITH CAUTION BECAUSE OLD CAPTIONS WILL BE OVERWRITTEN! *) (***** Change these lines *****) minyear=2000; maxyear=2000; minroll=114; maxroll=114; dir="e:\\public_html\\pictures\\archives"; (******************************) BeginPackage["takebetween`"] takebetween::usage = "If the string s mathes the pattern *s1*s2* then takebetween[s,s1,s2][[1]] is True and takebetween[s,s1,s2][[2]] is the string between s1 and s2, otherwise takebetween[s,s1,s2] is {False,{}}." Begin["`private`"] takebetween[s_String,s1_String,s2_String]:= If[StringMatchQ[s,"*"<>s1<>"*"<>s2<>"*",IgnoreCase->True], posit=StringPosition[s,s1,IgnoreCase->True]; drop1={1,posit[[1,2]]}; s12=StringDrop[s,drop1]; posit=StringPosition[s12,s2,IgnoreCase->True]; drop2={posit[[1,1]],StringLength[s12]}; s12=StringDrop[s12,drop2]; {True,s12},{False,{}}] End[] EndPackage[] Do[ (* year *) year=ToString[nyear]; Do[ (* roll *) roll=ToString[nroll]; dirroll=ToFileName[{dir,year,roll}]; If[SetDirectory[dirroll]!=StringDrop[dirroll,-1],Goto[1]]; browser0=ToFileName[dirroll,"browser0.htm"]; capt=ToFileName[dirroll,"captions.txt"]; Print[" ---------- ",capt]; data=ReadList[browser0,String]; mlines=Length[data]; oc=OpenWrite[capt,PageWidth->Infinity]; captnumb=""; Do[line=data[[nline]]; t=takebetween[line,"",""]; uline=ToUpperCase[line]; If[ t[[1]], title=StringReplace[t[[2]],": thumbnail preview of photo shots"->""]; Write[oc,"#ROLL"//OutputForm]; Write[oc,title//OutputForm]; Print["#ROLL\n",title]; Goto[2]; ]; line0=StringReplace[uline," "->""]; If[ StringMatchQ[line0,"*@&NBSP;"], captnumb=takebetween[line0,"","&NBSP;"][[2]];c="";Goto[2] ]; If[captnumb!="",c=c<>"\n"<>line]; t=takebetween[c," ",""]; If[ t[[1]], c=t[[2]]; c="#"<>captnumb<>": "<>c; captnumb=""; Write[oc,c//OutputForm]; Print[c]; ]; Label[2],{nline,mlines}]; Close[oc]; Label[1],{nroll,minroll,maxroll}],{nyear,minyear,maxyear}];