Microsoft KB Archive/65163

= How to Remove Spaces from an MS-DOS Filename or Subdirectory =

Article ID: 65163

Article Last Modified on 5/12/2003

-

APPLIES TO


 * Microsoft MS-DOS 3.1
 * Microsoft MS-DOS 3.2 Standard Edition
 * Microsoft MS-DOS 3.21 Standard Edition
 * Microsoft MS-DOS 3.3 Standard Edition
 * Microsoft MS-DOS 3.3a
 * Microsoft MS-DOS 4.0 Standard Edition
 * Microsoft MS-DOS 4.01 Standard Edition
 * Microsoft MS-DOS 5.0 Standard Edition
 * Microsoft MS-DOS 5.0a
 * Microsoft MS-DOS 6.0 Standard Edition
 * Microsoft MS-DOS 6.2 Standard Edition
 * Microsoft MS-DOS 6.21 Standard Edition
 * Microsoft MS-DOS 6.22 Standard Edition

-



This article was previously published under Q65163



SUMMARY
Although your application program may allow you to enter a filename or directory name that contains a space character, MS-DOS does not allow filenames or directory names to have spaces in them.

If you create a filename containing a space, you cannot subsequently remove, load, or delete the file unless you first rename it.

For example, if the file appears in the directory as   TEST CAR  TXT    4098  01-01-80  3:10pm then MS-DOS does not allow you to manipulate the file unless you delete the space between &quot;TEST&quot; and &quot;CAR.&quot;

If you create a directory name with a space in it, you must remove the directory.



MORE INFORMATION
When MS-DOS parses the command line, it separates the various parameters by looking for a space. MS-DOS commands and utilities view the filename &quot;AUG 1990.DAT&quot; as two parameters: &quot;AUG&quot; and &quot;1990.DAT.&quot; Commands such as ERASE, COPY, and RENAME return an invalid parameter error because it appears that an extra parameter is supplied.

Also, certain operations that application software can request MS-DOS to perform require a filename. If the filename supplied to MS-DOS by the application contains a space, MS-DOS may be unable to process the request.

Modifying/Removing a File
Use the following procedure to rename and then modify a file with a space in its name:

  Use the MS-DOS RENAME command with a wildcard to replace the space with a legal filename character. For example:      rename test?car.txt test_car.txt This example replaces the space with the underscore character.

This method prevents MS-DOS from separating TEST and CAR.TXT as two separate parameters, but still allows MS-DOS to find the file. The file is renamed to TEST_CAR.TXT, which is a legal MS-DOS filename.  Delete, read, or modify the file using normal procedures.

Removing a Directory
You can remove a directory that contains a space in its name by using the Basic interpreter, which is included in MS-DOS (GW-Basic, BASICA, or QBasic).

 Start GW-Basic, BASICA, or QBasic, by typing its name and pressing ENTER. In QBasic, press F6 to make the Immediate window active (this step is not necessary in GW-Basic or BASICA).  Use the MS-DOS RMDIR command to remove the directory. For example, use the following command to remove a directory called &quot;HI THERE&quot;: <pre class="fixed_text">     rmdir &quot;hi there&quot; (and press ENTER) GW-Basic or BASICA respond with &quot;OK&quot;; QBasic does not respond. </li> To exit QBasic, choose Exit from the File menu; to exit GW-Basic or BASICA, type system and press ENTER.</li></ol>

NOTE: If you are using MS-DOS 6.0, 6.2, or 6.21, you can use MOVE to rename illegal directories. For example, type the following at the MS-DOS command prompt:

move &quot;my work&quot; my_work

<div class="references_section">