Borland Online And The Cobb Group Present:


March, 1994 - Vol. 1 No. 3

Borland C++ 3.1 - Eliminating SWP files

If you regularly run early versions of your projects from the Borland C++ 3.1 Integrated Development Environment (IDE), you may have noticed the appearance of some files you didn't create. These files have names in the form TC0000.SWP, TC0001.SWP, and so on.

Although finding files you haven't created is bad enough, these files usually take up over 262 Kb of disk space each. In this article, we'll tell you what these mystery files are, how to eliminate them, and how you can prevent them in the future.

Swap Meet

When you launch the IDE, it creates a temporary file called a swap file to hold information that the IDE can't place in RAM. As the IDE needs different parts of this disk file, it "swaps" the information to and from the file.

When you shut down the IDE, it deletes this temporary file. Therefore, if you simply run the IDE and then exit, you'll never see a swap file left behind.

Early in your development cycle, you'll probably see some of your new DOS or Windows projects crash when you run them. Unfortunately, if you run those projects from inside the IDE, some of the crashes may cause the IDE itself to crash. When this happens, the IDE doesn't have the opportunity to close and delete the swap file. Later, when you relaunch the IDE, it will see the old swap file and create a new one with a different name.

The IDE always names the first swap file TC0000.SWP. If a project crashes while TC0000.SWP is open, the IDE will create TC0001.SWP the next time you launch it. Figure A shows a directory listing for an IDE that has crashed many times.


Figure A - Each time a project crashes the IDE, it leaves another unnecessary swap file behind.

C:\BORLANDC\BIN>dir tc????.swp

 The volume label in drive C is DOS6.
 The Volume Serial Number is 1234:5678
 Directory of C:\BORLANDC\BIN

TC0000   SWP    262144  11-23-93 12:26p
TC0001   SWP    262144  11-23-93 12:09a
TC0002   SWP    262144  11-23-93 12:28p
TC0003   SWP    262144  11-23-93 12:30p
        4 file(s)    1048576 bytes used
                    22900736 bytes free

C:\BORLANDC\BIN>

Deleting the Files

Fortunately, you can delete those swap files and reclaim the disk space they occupy. To do so, you'll first exit the IDE if it's running. You'll do this because it may be difficult to determine which swap file the IDE is using if you try to delete the files from the IDE's DOS shell.

Next, you'll scan your hard disk for any Borland C++ swap files. Since the IDE always stores the swap file in the directory you launched it from, you'll need to look in every directory in which you run Borland C++. One easy way to search for swap files anywhere on the disk is to use the DOS command

DIR C:\TC????.SWP /S

When you add the /S parameter at the end of the directory command, DOS will search all subdirectories for files that match the specification. You'll see the files for each directory separately, as shown in Figure B.


Figure B - By using the /S parameter, you can quickly search all subdirectories.

C:\BORLANDC\BIN>dir c:\tc????.swp /s

 The volume label in drive C is DOS6.
 The Volume Serial Number is 1234:5678

 Directory of C:\NEWPRJ

TC0000   SWP    262144  11-16-93 12:01p
        1 file(s)     262144 bytes used

 Directory of C:\BORLANDC\BIN

TC0000   SWP    262144  11-23-93 12:26p
TC0001   SWP    262144  11-23-93 12:09a
TC0002   SWP    262144  11-23-93 12:28p
TC0003   SWP    262144  11-23-93 12:30p
        4 file(s)    1048576 bytes used
                    22900736 bytes free

C:\BORLANDC\BIN>

Then, you'll simply delete the swap files by executing the DOS command

DEL TC????.SWP

in each directory that contains swap files. This will remove any swap files you have on your PC.

Preventing Unnecessary Swap files

To prevent swap files from accumulating in the future, we'll create a batch file that automatically eliminates the swap files each time you run the IDE. As a result, there won't ever be more than one loose swap file in any given directory.

To make sure our batch file is as accessible as the IDE is, we'll put it in the \BIN directory with the IDE's executable file. In addition, we'll be sure to pass to the IDE any source file or project that we pass to the batch file. Now, let's create a NO_SWAP batch file.

At a DOS command line, enter

COPY CON C:\BORLANDC\BIN\NO_SWAP.BAT
DEL TC????.SWP
BC %1

When you finish entering the batch file, save it by pressing [Ctrl]Z and then pressing [Return].

The DEL command in this batch file deletes any files in the current directory that match the TC????.SWP format. If you use *.SWP instead, you might delete the swap files for some other application.

The last line in the batch file runs the Borland C++ IDE for DOS by using the command BC. The %1 immediately following BC passes any source or project filename from the batch file's command line as a command-line parameter for the IDE.

To use the NO_SWAP batch file, you can launch the IDE with a project by entering

NO_SWAP TEST.PRJ

instead of

BC TEST.PRJ

Now, the batch file will delete any swap files in the current directory that remain from an IDE crash.

Return to the Borland C++ Developer's Journal index

Subscribe to the Borland C++ Developer's Journal


Copyright (c) 1996 The Cobb Group, a division of Ziff-Davis Publishing Company. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of Ziff-Davis Publishing Company is prohibited. The Cobb Group and The Cobb Group logo are trademarks of Ziff-Davis Publishing Company.