| Home | “This is the only version of the only program that I ever use to do a multiple file search and replace. There is no need for any other program. It does everything that you could possibly want to do!” |
A. Introduction
B. Assumptions
C. Get the Free Download
D. Main Features
E. Demo: Change the Sample Web Page File
F. Preview Mode
G. Subfolder Support
H. The Tutorial
This web page is a tutorial on how to use MFP (Multiple File Parser) to do multiple-file search and replace operations of almost unlimited complexity, even if the files are located in multiple subfolders (subdirectories). This Perl script, in the form of a .bat file, never has to be changed. All of the code for how to do the search and replace operations are contained in a separate .perlcode file, which is to be dragged and dropped on top of the MFP_DragAndDropPerlCodeOnMe.bat - Shortcut icon on your computer’s desktop.
This is the only version of the only program that I ever use to do a multiple file search and replace. There is no need for any other program. It does everything that you could possibly want to do! And now that it can also handle files with names that contain Unicode characters, it is even more powerful.
Although the examples contained in this tutorial have to do with changing multiple web page files, the exact same methods may be applied to any group of text files. (By using the word, “Examples,” I am referring to the example (demo) below plus the many other examples which are “commented-out” in the included _MFP_SearchAndReplace1.perlcode file.)
This tutorial assumes the following:
1. That extensions for known file types are not hidden: a) Click Start. b) Click Computer. c) Click Organize. d) Click Folder and search options…. e) Click the View tab. f) Make sure that Hide extensions for known file types is unchecked. g) Click OK. h) Close the Computer window.
2. That you have Notepad2 or a shortcut to it on your desktop.
3. That you have installed Perl: a) Go to http://www.activestate.com/activeperl/downloads. b) Download the free version of ActivePerl for Windows. c) Install it, making sure that Add Perl to the PATH environment variable is checked (the default).
4. That _MFP_DragAndDropPerlCodeOnMe.zip (2.47 KB) has been downloaded, unzipped to a folder named _MFP_DragAndDropPerlCodeOnMe, that the _MFP_DragAndDropPerlCodeOnMe folder is located somewhere on your computer’s hard drive, and that a shortcut to the _MFP_DragAndDropPerlCodeOnMe.bat file within that folder is located on your computer’s desktop.
5. That the MFP_DragAndDropPerlCodeOnMe.bat file has a “Date modified” of 1/24/2015 or later.
1. Download _MFP_SearchAndReplace.zip (3.29 KB)
2. Unzip _MFP_SearchAndReplace.zip to a folder named _MFP_SearchAndReplace.
Caution: Be sure to keep unchanged versions of all of the files that you change. The backups should be in a separate folder, or, better yet, on a different drive.
1. A log file, corresponding to the particular .perlcode file, is created which lists all files which were changed and how many changes were made to each.
2. Files are not rewritten unless they are actually changed. Therefore, changed files may be easily separated from unchanged files by sorting by “Date modified.”
3. Individual files are only opened once, even if, for example, multiple global search/replace operations are done in one fell swoop. (Much faster.)
4. “Preview mode” allows one to go through the motions of making changes without actually making them. Therefore, if the files changed and/or the number of changes being made is not what was expected, then the error can be corrected without “messing things up.”
5. There is no user interaction during run time to slow things down.
6. Any number of files can be changed in one fell swoop.
7. Multiple file types may be changed, in one fell swoop, without changing all file types.
8. The files may be a mixture of encodings: ANSI (ASCII), Unicode (UTF-16), and/or UTF-8 (with or without signature).
9. If the .perlcode file is encoded as UTF-8 with signature, then changed files encoded as ANSI are automatically converted to UTF-8 with signature.
10. If the .perlcode file is encoded as ANSI, then the encoding of ANSI files is not changed.
11. Changed files encoded as Unicode or UTF-8 without signature are always converted to UTF-8 with signature.
12. Files with names containing Unicode foreign language characters are handled seamlessly.
The way this demo works is that first the .demo file is copied to a .htm file. Then the Perl code in the _MFP_SearchAndReplace1.perlcode file is applied only to the .htm file. Thus, for the purposes of this demo only, the results will be exactly the same every time that it is run, as long as no changes are made to the .demo file or to the .perlcode files.
1. Open the _MFP_SearchAndReplace folder. It contains 5 files:
2. Double-click on the _MFP_PrepareTheDemo.bat file icon. Then you should see that a new .htm file has been created:
Please observe the contents of this .htm file: