A Problem with File Extensions


Downloading data from the ME 352 or NMM web sites is relatively easy. You simply click on a link and decide where to save the file. This apparent simplicity hides a little problem with file extensions for users of Microsoft Windows. This problem is an annoyance for experienced users, and a source of confusion for inexperienced users.

The problem is that depending on the steps you use to download and save the file, Internet Explorer might add a .txt file extension to documents that have are stored on the web with .dat or .m extensions. In some cases, Internet Explorer replaces the period (dot) in .dat with an underscore.

As a result of this undesirable behavior you must pay attention to file extensions. It is also important to realize that this is not a MATLAB error, or MATLAB's fault, or a problem with the ME 352 or NMM web sites. Yes, MATLAB may have trouble reading the file, but only because Internet Explorer has changed the file extension when it saved the file. Internet Explorer changes the file extension without telling you.

File Extensions

File extensions are used to indicate the content of a file and the application (software program) appropriate for working with that content. Here are some common file extensions and their conventional associations on the Microsoft Windows operating system.

doc   Microsoft Word
ppt   Microsoft PowerPoint
xls   Microsoft Excel
txt   NotePad.

The default behavior on Windows computers is that documents with the extension in the first column will be opened by the application in the second column. For example, double-clicking on foo.doc will cause Microsoft Word to open foo.doc. This automatic association of files with an appropriate application is a good thing.

But I Can't See the File Extensions!

Suppose you had a folder with three files: AltensileTest.dat, PS1_solution.doc, and tensileTest.m. The AltensileTest.dat file contains data in plain text format. The PS1_solution.doc file might be the Microsoft Word document containing your solution to Problem Set 1. The tensileTest.m file is a MATLAB function (program). With the default settings of Windows/XP, the list view of the folder containing those three files would look like Figure 1.

Window showing icons without file extensions

Figure 1: The default folder display option is to hide file extensions.

Note that the appearance of the folder is also affected by the view options. Select "View" >> "List" for the list view shown in this example.

The MATLAB program (tensileTest.m) and the Word document (PS1_solution.doc) in Figure 1 have icons that indicate the applications with which they are associated. However, the file extensions are invisible. This is the default behavior of Windows/XP. To make the file extensions visible, perform the following steps

  1. Click on the folder to bring it into focus
  2. Select "Tools" >> "Folder Options"
  3. Select the "View" tab
  4. Uncheck the "Hide extensions for known file types" box
  5. Click "OK"

For our example folder containing AltensileTest.dat, PS1_solution.doc, and tensileTest.m, the folder would now appear as in Figure 2.

Window showing icons with file extensions

Figure 2: After changing the folder display option so that file extensions are shown.

Dowload While Retaining (or Fixing) the Extension

There are at least two ways of dealing with the possibility that Internet Explorer might change a file extension. The first and recommended procedure is to use the Save target as method. The second is to fix the file extension after the download. Even if you use the recommended Save target as approach, you should be aware of how to fix the extension after downloading a file.

Using the "Save Target As" method

The following steps will allow you download files with .dat and .m extension without having to clean-up the file extensions later.

  1. Go to the URL with the link to the file you wish to download
  2. Right-click on the link to the file, and select "Save Target As ..." from the pop-up list
  3. Navigate to the directory where you wish to store the file
  4. Verify the file name in the "File Name" box, and make any changes, but do not change the file extension. Refer to Figure 3, below.
  5. Make sure "Text Document" is selected in the "Save as type" box.
  6. Click "OK"

The file should now be saved as a plain text document with the extension it has on the ME 352 or NMM web site.

Dialog box for downloading a text file

Figure 3: Dialog box for downloading a text file with the "Save Target As" method.

Fixing the Extension After Download

The problem with file extensions occurs if you use an obvious way to download a file:

  1. Go to the URL with the link to the file you wish to download
  2. Click on the link to the file. This (usually) displays the file content in your browser window.
  3. Select "Save As" from the "File" menu in the browser
  4. Navigate to the directory where you wish to store the file
  5. Click "Save as"

If you follow this sequence in Internet Explorer, the Save as step causes the problem. Figure 4 shows the dialog box that Internet Explorer presents when you select "Save As" from the "File" menu. In particular, this is the dialog box that appears if you try to save the AltensileTest.dat file from the preceding examples.

Dialog box for saving a browser window

Figure 4: The Internet Explorer dialog box that results from clicking "Save As" when you are viewing a document displayed in a browser window.

Note that the title of the dialog box in Figure 4 is "Save Web Page". Also note that the file name has been changed from AltensileTest.dat to AltensileTest_dat: the period has been replaced with an underscore. Although the user clicked on a link to a .dat file, IE ignores the original file extension and assumes you want to display the contents of the browser window as an HTML document. To my knowledge, there is no graceful way to recover other than clicking the back button and using the Save Target As method described above.

To complete the thread of the current example, suppose that you want to save the file anyway, even though IE thinks you want to save it as an HTML document. The solution is to select "Text File (*.txt)" in the "Save as type" field near the bottom of the dialog box. Doing so in IE version 6, causes the file AltensileTest_dat.txt to be saved in the target directory. To make this file useful — or to at least return it to its original name — you need to change the file extension in the Windows file browser. Here are the steps:

  1. Locate the file in the Windows File Browser
  2. Make sure that the file extensions are visible.
  3. Rename the file using the correct extension.
  4. Ignore the warning about the dangers of changing the file extension.

The warning about changing file extensions is a ruse to scare inexperienced users from straying from the Microsoft fold. Figure 5 shows the warning message.

Windows warning about changing file extensions

Figure 5: The warning message about changing a file extension.

If you change the file extension to one that is not currently recognized by Windows, then you will not damage the file. Rather, when you double click on that file (with the changed extension) you will get a message indicating that Windows does not know which application should be used to open the file. The only problem is that the built-in association with a particular application is lost. When you double-click on a file that is not associated with any application, windows presents you with a dialog box for choosing the application for opening the file. If you do not wish to use that dialog box, you can restore the association by changing the extension back to one that is recognized by Windows.

A Rant

Note that the warning message in Figure 5 is not displayed if you change the file extension from .dat to one that is associated with a Microsoft product. For example, if you change the extension from .dat to .doc, there is no warning. There will be no complaints from Windows because you are taking a neutral document (a plain text file) and associating it with one of Microsoft's applications. Double-clicking on the file that used to be a .dat, but now (through an extension change only) appears to be a .doc file will open the file with Microsoft Word. If you then try to save the file from within Microsoft Word you will get further warnings that something will be lost if you choose to save your document in a format unfamiliar to a Microsoft application.

Clearly there is some advantage to warning users about accidental changes to their files. However, the warnings are not universal, and they are always trying to steer the user away from neutral file types and toward a proprietary and closed file types. Finally we note that this behavior does not occur on the Mozilla browser on Windows, Macintosh, and Linux, nor on Internet Explorer or the Safari browser for Macintosh. There is no technical reason why the original file extension cannot be retained when a file is opened in Internet Explorer for Windows.