CopyFile Command Altered by Hide MS-DOS Extension Option

ID: Q134808

The information in this article applies to:

SYMPTOMS

When you use the WordBasic command, CopyFile, the copy of the file does not have an extension. As a result, the copied file loses its association with Microsoft Word and becomes a generic Windows 95 file. The following code results in this problem:

   Sub MAIN
   CopyFile "c:\storage\test.doc", "c:\temp"
   End Sub

CAUSE

This problem occurs when the "Hide MS-DOS file extensions for file types that are registered" is checked in Windows Explorer. (To locate this option, in Windows Explorer, click Options on the View menu.)

STATUS

Microsoft has confirmed this to be a problem in Microsoft Word for Windows 95 version 7.0. This problem was corrected in Word version 7.0a for Windows 95.

RESOLUTION

To work around this problem, use one of the following methods to preserve the copied file's association with Microsoft Word.

Method 1. Make sure the "Hide MS-DOS file extensions for file types that

          are registered" option in Windows Explorer is not checked.

Method 2. Use the Declare command to make a CopyFileA call to
          Kernel32.dll. To do this, use the following macro:

          NOTE: The sample assumes that you have a Microsoft Word document
          called "Test.doc" located in the C:\Storage folder.

          Declare Function CopyFileA Lib "kernel32"(a$ As String, b$ As
          String, n As Integer) As Integer

          Sub MAIN
             x = CopyFileA("c:\storage\test.doc", "c:\temp\test.doc ", 3)
          End Sub

          NOTE: Using a number greater than 0 in the above example will not
          overwrite an existing file. The file specified as the destination
          remains the same. However, if 0 is used, as in the example below,
          the destination file will be overwritten by the specified file if
          it exists in the specified directory.

          Declare Function CopyFileA Lib "kernel32"(a$ As String, b$ As
          String, n As Integer) As Integer

          Sub MAIN
             x = CopyFileA("a:\test.doc", "c:\test.doc ", 0)
          End Sub

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

KBCategory: kbusage buglist7.0 fixlist7.0a KBSubcategory: kbmacroexample

Additional reference words: 7.0 word95 copyfile copy file wordbasic word7 winword word basic macro example 6.0 6.0a 6.0c 7.0 7.0a 2.0 2.0a 2.0a-cd 2.0b 2.0c

Keywords          : kbmacroexample 
Version           : 2.x 6.0 6.0a 6.0c 7.0 7.0a
Platform          : WINDOWS

Last Reviewed: February 6, 1998