Jump to content
Macro Express Forums

Global text replacement inside MEX files?


Recommended Posts

A hundred or so of my macros contain text like this, such as in TextType and Program Launch commands, etc:

C:\Docs\Sundry\FolderABC\filexyz.txt

 

I've just reorganised my HD. All subfolders of \Sundry\ have been moved up the tree to \Docs\. So that text above has to be changed to

C:\Docs\FolderABC\filexyz.txt

 

One extremely tedious way of doing it would be to identify all those macros (itself not a trivial task as I have over a thousand, in about 70 categories, and these particular ones can occur just about anywhere) and then open each one individually, locate the command(s), and change them manually, re-saving the macro.

 

I thought I'd found a smart way instead. I opened the MEX file in my rarely used hex editor (Hex Editor Workshop). Then I used its Replace facility in this dialog:

 

MEPro-GlobalReplace-1.jpg

 

I'm not a programmer or 'techie' so initially I didn't checkmark that option 'Pad with Nulls'. Presumably the new file was therefore a different size to the original, apparently verboten in the world of Hex.

 

This is what Help says:

"The Replace Utility allows for different sized search and replace strings, and has a Replace All option. In addition, the Replace Utility offers an option to "Pad String with Nulls" when replacing ASCII. This is useful if you are replacing a string with a shorter string and with to leave the file size intact. The replace string will be padded with NULL chars until it is equal in size to the search string, before substituted."

 

So I ended up with an MEX that ME Pro regarded as corrupted. But re-trying with that option duly checkmarked all seemed well, the edited MEX opened and all my macros appeared intact. But on testing some of them I was disappointed to find that all entries like

C:\Docs\Sundry\FolderABC\\filexyz.txt

were now like this:

C:\Docs\

 

All the rest had vanished.

 

Can any of the programmers here tell me what my misunderstanding is, and how I might correct it please?

 

Or, if that hex editing approach is doomed for failure, any other ideas?

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

When I maintained the PGM library, I wrote a macro to edit other macros - each of our macros had a multi-line header which contained data for other functions, e.g. the Help stuff we provided; when we needed to add or change this header information, we had to do it in all our PGM macros, so the only way forward was to write a macro to do this. Your requirement here sounds similar and more straight-forward.

Link to comment
Share on other sites

First off don't ever use magic references like this. I usually use an INI file (networked) for common folders like where all the client's folders reside or the Db extracts. This way I can edit one string and no macros if things move. Also I often use the macro's folder from the Get Macro Path command as a sort of relative path to all the support files for the macro. This way I can create a macro folder with all the usual bits I need and it's totally portable with no re-coding. Also handy as it can be used as a development environment.

 

Most file like this can't be directly edited in this way I just tried editing a MEX file with out the null padding and that doesn't work either. Sometimes all the program checks is the length of the file. If one pads with nulls one can often fake it out. But MEP probably does a checksum or other verbose method so the short answer is you can't mess with a MEX directly.

 

You can export the script using the "Output Macro Information" feature, edit it and import. But although one can export multiple macros importing doesn't recognize names, activation or multiple macros and stupidly lumps it all into one macro. I just posted a feature request to fix this. BTW long ago I requested a global replace feature.

 

I had essentially this same problem when converting from ME to MEP and my fix was to write a reporting macro. What you do is export to a Macro Info file then run the macro against it with a provided string. It then returns a report of every macro and line number that string occurs on. Not an ideal fix but at least it allows you to target your find/replace. Beware that in info files backslashes in paths are escaped with double backslashes. There may be others so find an example first in the text editor before doing the search.

Link to comment
Share on other sites

Thanks for that thorough reply, Cory.

 

If I'd anticipated the sort of change I've just made to my folder structure some years ago, I might have considered the sort of approach you suggest.

 

The failure of the hex editing approach is frustrating. I can't help thinking there's some clever trick or setting that would fix it!

 

It was in fact your old macro I used to find the target occurrences - a very handy tool. I didn't know about the \ issue, so had to settle for a less focussed target of 'sundry', but that was no major problem.

 

I've now written a couple of simple macros to assist, so it's now a 'hybrid' approach, manual plus macros. Should finish it in another couple of hours.

 

--

Terry, UK

 

 

Link to comment
Share on other sites

Hi you could have just created a symbolic link to the old directory (like an alias or shortcut), so your macros could just chug along thinking nothing has changed.

 

The Junction utility from Sysinternals does this:

 

http://technet.micro...s/bb896768.aspx

 

But as Cory noted, it's not a good practice to hard-code directory paths!

 

Update: You can also do this in Vista or Win 7 with the built-in Mklink command:

 

http://www.maximumpc.com/article/howtos/howto_use_symbolic_links_master_vistas_file_system

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...