This procedure will be the first under the root directory of all documents loaded into the list
Through dir2list function
While (true) (
Cout << "input the root directory:" <<endl;
Cin>> tmpchr; rootdir = tmpchr;
If (! Regex_match (rootdir, Eisfolder)) continue;
Cout << "input the new root directory:" <<endl;
Cin>> tmpchr; rootdirnew_root = tmpchr;
If (! Regex_match (rootdirnew_root, Eisfolder)) continue;
Break;
)
Dir2list (rootdir);
Central to escape through each treatment
Code as follows:
For (i = 0; i <lstfile.size (); i + +)
(
Relink (lstfile [i]);
Fprintf (stdout, "% d /% d / r", i +1, lstfile.size ());
Fflush (stdout);
)
Relink the main uses regex expressions
Void relink (string path)
(
Ifstream inf; long int length, lasttimepos, lenwhatfore;
Tmp4 = path.substr (rootdir.length ());
Replace (tmp4.begin (), tmp4.end (), '/ /','-');
Rootdirnew = rootdirnew_root + tmp4;
If (! Regex_match (path, filefilter_regex))
(CopyFile (path.c_str (), rootdirnew.c_str (), false);
Return;
)
Smatch what;
Regex EUrl ( "(href = / ")(.*?)( / ")");
Std:: string:: const_iterator start, end;
Inf.clear (); strcpy(buffer,"");
Inf.open (path.c_str (), ios:: ate | ios:: in);
Length = inf.tellg ();
Inf.seekg (0, std:: ios:: beg);
Inf.read (buffer, length);
Oldctt = buffer;
Start = oldctt.begin (); end = oldctt.end ();
Lasttimepos = 0;
Newctt = ""; lenwhatfore = 0;
While (regex_search (start, end, what, EUrl)) (
If ((int) what [2]. Str () [0] == 35) / / #
(+ What.position lenwhatfore lenwhatfore = () + what [0]. Str (). Length ();)
Else if (what [2]. Str (). Compare (0,7, "http://") == 0)
(+ What.position lenwhatfore lenwhatfore = () + what [0]. Str (). Length ();)
Else
(
Lenwhatfore = lenwhatfore + what.position ();
Tmp2 = path.substr (rootdir.length ());
If (tmp2.rfind ( "/ /")! = String:: npos) tmp2 = tmp2.substr (0, tmp2.rfind ( "/ /")); else tmp2 = "";
Tmp3 = what [2]. Str ();
While (! Tmp3.compare (0,3 ,"../"))
(
Tmp2 = tmp2.substr (0, tmp2.rfind ( "/ /"));
Tmp3 = tmp3.substr (3);
If (tmp2.rfind ( "/ /") == string:: npos) (tmp2 ="";}
)
Replace (tmp3.begin (), tmp3.end (),'/','-');
Replace (tmp2.begin (), tmp2.end (), '/ /','-');
If (! Tmp2.empty ()) fulldir = tmp2 + (string )"-"+ tmp3; else fulldir = tmp3;
Newctt = newctt + oldctt.substr (lasttimepos, lenwhatfore) + what [1]. Str () + + fulldir what [3]. Str ();
Lasttimepos lenwhatfore + + = lasttimepos what [0]. Str (). Length ();
Lenwhatfore = 0;
)
Start = what [0]. Second;
)
Newctt = newctt + oldctt.substr (lasttimepos);
Ofstream outf (rootdirnew.c_str ());
Outf <<newctt.c_str ();
Inf.close ();
Outf.close ();
)