We help IT Professionals succeed at work.
Get Started

Search for string in file, save another file and paste data tin new file

437 Views
Last Modified: 2014-08-16
We have a directory in c:\data and it contains hundred of sub directories and we want a batch to do a search of a text inside a file the once found create a new file and copy the content there. Here is the procedure:

1.-Directory with c:\data and inside there hundred of sub directories.
2.-On each sub directory there is a file called res2.html
3.-The script ON ALL files res2html inside each one of the hundred sub directories we need to check for:
4.-Search for the string "flv=../../../activ/" and store in a variable called A.
5.-Then search in same res2.html files for this other string "/videos2_1/video2_1.flv" and we can call B.
6.-Then between A and B in the middle of the both files there is a word that word we can call variable C.
7.-After find C and have located A and B also, the script must create a .html file with the name of the contents of the variable C and ending in .html. For example if C variable has a content called "course234" (without quotes of course) the resulting file must has the name "course234.html".
8.-For last step inside the file created "course234.html" the content stored there must be A+C+B.
9.-Process all the res2.html files inside all sub directories inside c:\data no matter if there is a need to process 1-8 steps for hundred of sub directories i side c:\data.

   To clear the example we have according above we have in A="flv=../../../activ/" and B="/videos2_1/video2_1.flv" and suppose the variable C, the word in the middle between A and B found by the script is the fictitious name "course234" (all without quotes of course). Then the script must create a file like C name ending in html in other words the new file created in the same directory is "course234.html" and inside of that new file created the content must be A+C+B in other words the content inside "course234.html" is "flv=../../../activ/course234/videos2_1/video2_1.flv" and again and like always without quotes.
   We don't know if this could be made in a batch of command prompt or maybe a visual basic script. I hope someone could help with the script, one way or another the script must run from command prompt. Could be .bat or .vbs.
Thank you
Comment
Watch Question
Get vaccinated; Social distance; Wear a mask
CERTIFIED EXPERT
Top Expert 2014
Commented:
This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE