New Tricks for an Old DOS30 Sep, 2015 By: Bill Fane
Learning Curve: Sometimes, you can do things with an old-fashioned DOS command prompt that Windows can’t do at all.
It was a warm and sunny afternoon. Captain LearnCurve’s son Trevor was visiting from Adelaide, Australia, where he and his wife Jenn are currently living. While driving the ski boat, Trevor captured some images of the Captain waterskiing.
Captain LearnCurve’s son Trevor provided this caption: “Selfie with Dad. He’s the one on the end of the rope. He’s 72.”
That’s it! The topic for this article!
Old things performing cool tricks.
I say again, Huh?
For all the cool things that Windows can do (such as sucking up system resources, multitasking so minor programs can keep bugging you regularly to install the latest update when you’re trying to do useful work with a major program, crashing at the worst possible time, and so on), there are times when an old-fashioned disk operating system (DOS) command prompt can perform better than Windows. In fact, as you’ll see if you read on, there are things that can be done using the DOS prompt (also known as the system command prompt) that Windows can’t do at all.
Here’s an example: Suppose you’re working on a very large project, which involves several thousand drawings in a multibranch folder structure that is several layers deep. Mixed in are several thousand Word documents, Excel spreadsheets, and raster images in a variety of file formats.
Your boss comes out of her office to announce, “The client and I are going out for lunch. When we come back, he wants a copy of all the AutoCAD drawings for the project that are new or have been revised since a week ago Tuesday, maintaining the original folder structure. Oh, and be sure to include a printout of all the file names. Thanks.” Most people’s first reaction is that this could take hours, or even days! By the time they get their coats on, however, you meet them at the door with the printout and a USB flash drive containing the desired files. “Join us for lunch?” invites the surprised client.
Impossible? No, not if you use the system command prompt.
To start, plug an empty USB flash drive into your computer. Use Windows Explorer, and note its drive letter under My Computer. Now click the Windows Start button, then All Programs > Accessories > Command Prompt.
This brings up a good old DOS screen, as shown below. For you kiddies in the room, this was the main screen for all computers that ran DOS before Windows came along. Back in the day, you launched an application such as AutoCAD by entering its name (ACAD.EXE) at the system command prompt.
The black screen of DOS, showing the system command prompt.
By default, you are now in your My Documents folder. Assuming your USB drive is drive E: simply enter the following at the system command prompt:
xcopy *.DWG E: /d:08-14-2015 /s
Now watch in shock and awe as the desired files are automatically found and copied to your USB drive, while I explain what’s happening:
- XCOPY is the eXtended Copy command. Earlier versions of DOS only had Copy, which was much more limited in what it could do.
- *.DWG tells it to only copy files with the DWG extension in their names. By default it copies starting from the current folder. More on this later.
- E: tells it to copy to the current folder on drive E: (which is your USB drive in our example).
- /d:08-14-2015 tells it to only copy files that were created or modified on or after the specified date. The date format for North American computers is usually mm-dd-yyyy but this may vary in other parts of the world. In our example, it’s August 14, 2015.
- /S tells it to search down through all folders and subfolders looking for DWG files. Any that it finds that meet our date criteria will be copied to the E: drive in a folder structure that it creates to mirror the source.
By the time you finish reading the previous explanations the job will probably be done, and you can get working on the printout of file names.
Put That in Your Pipe and Print It
In a previous article, “Seek and Ye Shall Find: Quickly Locate AutoCAD Files That Contain Specific Entities,” I showed how to use the system DIR command to obtain a directory listing of selected files and folders. That article also showed how to redirect the DIR command’s output and pipe it to a simple text file instead of to the screen. We then edited that file to turn it into an AutoCAD script that batch-processed a number of files.
Ah, but it gets better! You can redirect the output of almost any system command. For example,
xcopy *.DWG E: /d:08-14-2015 /s > new-files.txt
produces the text file listing directly, without having to go through the DIR command. You won’t see anything happening on screen, but when XCopy is finished you can open the target TXT file using Notepad to see the results. Print it, and while you’re at it why not also copy it to the USB drive as a bonus for the client? With that, you’re ready to go for lunch.
Let’s Do Lunch
Okay, now that you’ve enjoyed a nice lunch break, let’s look at the options available for the XCopy command. Enter the command and option
to bring up a listing of all 26 options, as shown below.
The XCopy command has 26 options!
The good news is that most are quite esoteric and rarely used, so I’ll just touch on the ones that you are most likely to use.
The source field is mandatory and specifies the files to be copied. Wild cards are acceptable, so that *.* means “everything,” *.DWG means “all drawings,” ABC??.DOC means “all Word DOC files whose name starts with ABC followed by any two other characters,” and so on. If no specific folder path is specified, then it starts from the current folder.
Here’s a shortcut that can save a lot of typing: When specifying a folder path, a single period means “the current folder,” so it isn’t necessary to specify the full path all the way down from the root of the drive. For example, if the current folder is c:\documents and settings\administrator\my documents and you want XCopy to start copying drawings from c:\documents and settings\administrator\my documents\Project 23, you don’t need to type the full path. All you need to enter is “.\Project 23\*.dwg” to have XCopy start from the Project 23 subfolder. (Note that quotation marks are required if the folder path or file name specification contains any spaces.)
[destination] is optional. If it isn’t present, then XCopy copies the selected files to the current folder, but for this to work the source location must be different from the current folder. A good example of this is when your client returns to his office. There are two ways of getting files from the USB drive into the client’s machine. One way is to simply drag and drop using Windows Explorer; the other way is to use XCOPY. If the client invokes a system command prompt, and if the USB drive is identified as E: on this machine, then XCOPY e:*.* /s /y will copy all files from the USB drive to the current folder, maintaining the folder structure. This means all files; be careful what you leave lying around on a USB drive that you are giving to someone else. (You don’t want to know how I know some of the things I know!)
- /d with no date specification copies all files newer than any it might find in the destination, including new files. I use this option to synchronize my console’s internal drive with the 2-terabyte USB drive I use with my laptop.
- /y means yes — without it, if a particular file name already exists on the target drive, then XCOPY will stop and ask if you want to overwrite it. The /Y parameter tells XCOPY to always answer “yes” and to copy over any existing files without asking. If the recipient of the USB drive uses XCOPY e:*.* /s /d /y then any existing files in the destination that are newer than on the USB drive will get overwritten without warning, even if the USB files are older. On the other hand, if you run XCOPY without the /Y parameter then it will ask “Are you sure?” every time it encounters an existing file in the destination location. (I’ve heard it said that if Microsoft built cars, the air bags would ask “Are you sure?” before they deployed.)
- /L displays a list of which files would be copied if /L wasn’t invoked. This is handy for checking that you haven’t made a slight typing error and are trying to dump your entire network file server onto your piddly little USB drive.
- /? displays the Help screen shown in Figure 3.
Now here are a couple of options you probably don’t want to use, because they can be misleading.
- /a stands for archive, and copies files whose “archive bit” is set. The archive bit is normally on when a file is created or edited. Backup software doing an incremental backup of new or revised files looks for this bit. If it is on, then the file is copied and the bit is turned off. It thus copies only those files that have changed since the last backup. The problem is that it doesn’t check the date, so that an older file whose archive bit is on will copy over a newer version of the file in the destination.
- /u only updates those files that already exist in the destination, but doesn’t copy new files.
There’s No Escape
Oops, you made a small error and XCOPY is busy dumping your entire hard drive to your cloud file-storage account. No problem, just hit your Escape key. Hey, what’s wrong? XCOPY won’t quit! Yes, early computers used Telex or Teletype keyboards that didn’t have an Escape key. The system command prompt continues this tradition, so you need to press Ctrl+C to cancel any command in progress.
You’ve certainly made an interesting case for using the system commands!
Speaking of case, none of the commands, paths, or options are case-sensitive, and the /options are not order-sensitive.
And Now for Something Completely Different
It’s actually quite simple to remove the sunroof panel from a 1937 Rolls-Royce Phantom III. The panel slides on two rails, each held down by four screws, but with the panel fully open only the front three screws are visible. No problem; simply remove the visible screws. The rails will now straighten up away from the curve of the roof and the panel will easily slide forward and off.