# How to transform a DumpSaved .mx file to .m file conveniently?

I have many DumpSave-d .mx files under a directory. They are generated under Linux. The .mx files are platform dependent, but I want to use the data stored in these .mx files under Windows.

So I want a method to transform a batch of .mx files into platform independent .m files conveniently.

-
Related: (2900), (25027) –  Mr.Wizard Jul 21 '13 at 10:55
This is a good example why DumpSave is not a good way to save data. Instead of DumpSave use Export which doesn't write variable names into the file and makes automatic format conversions easy, should you ever need them in the future. You can use mx with Export, but it's probably better to Compress the expression and Export it to "String" instead. –  Szabolcs Mar 16 '14 at 14:59

This is an interesting question but I'm not sure it's solvable in a general way. MX files are not really definitions but rather low level kernel state data, as I understand.

A potential, limited method would:

1. Record a "snapshot" of all definitions

3. Record a second "snapshot" and look for changes

4. Copy new/changed definitions and export them to a .M file

To even attempt this it would be helpful to to define limitations of the class of data in the .mx files.
For example: are they all OwnValues/DownValues definitions made in the same (Global?) context?

A rough start of this is shown in answer to: DumpSave for the forgetful

-
You are right. I forgot that in the general case I even don't know what variable hold in those .mx files. Anyway, in terms of my problem at hand right now, situation is simpler. These .mx files stored same set of variable, so I can skip the step find changes between two snapshot, but I still don't know how write codes to solve this simpler problem. –  matheorem Jul 21 '13 at 11:15
I mean how to do it in a batch mode. I lack experience in file manipulation. If I do it manually, I have to manully change filename, I just <<name1.mx then Save["name1.m",{symbol1,symbol2,...}]  then Clear[symbol1,symbol2,...] ,...... –  matheorem Jul 21 '13 at 12:06
@matheorem I'm about to leave for the day so I cannot work out the details, but you mean you have the names symbol1, symbol2 etc. that represent all the data you need to copy? In that case you should be able to use a loop like Do[Get[filename]; Save[StringDrop[filename, -1](* drop "x" *), {symbol1, symbol2, ...}]; Remove[symbol1, symbol2, ...];, {filename, listOfFileNames}]` -- which isn't far from what you just wrote. I'm not sure if this is helpful or not. –  Mr.Wizard Jul 21 '13 at 12:37