Command Line Usage


© Tracey Kirkpatrick-Pritchett

As PCWeek's NET ADVISOR columnist Neil Plotnick remarked in his 5/11/98 article, "Must be that ol' DOS magic":

    Experienced DOS users will often find that command line operations are faster and more efficient than those done with a GUI. Batch files can be written to automate complex and repetitive processes. Furthermore, all of this power comes bundled free with the operating system.

Renaming Files

Batch renaming files in a single directory can be simple using rename (or ren). It requires only the use of a wildcard in the command:

    ren *.htm *.html

(which would give all HTM files in the current directory the HTML extension)

If you want to batch rename files across directories and sub-directories, you can use the FOR command (which runs a specified command for each file in a set of files) with the /R (for recursive) switch:

    for /r %a in *.htm do ren "%a" *.html

Two notes here about the variables in the FOR command:
  1. when used in a batch file, the variable has to have two percent signs:
        for /r %%a in *.htm do ren "%%a" *.html

  2. and the final variable should have quotation marks around it in order to work with long filenames

Note: PC Magazine's June 9, 1998 issue features a new freeware utility add-on for Explorer called MultiRen, which lets you rename multiple files by first selecting them in Explorer, then selecting MultiRen from the right-click menu.

Parsing Text Files

The FOR command is good for working with a set of files across directories using any NT command, including NT's findstr command (which searches files for a text string):

    for /r %a in (*.htm) do findstr string "%a"

Note that the findstr command can use literals as well as regular expressions, so you could search for HTML tags around specific text, for example. See the NT Help file for more information about findstr switches.

Don't forget NT's graphical Find dialog (available from the Start menu), which parses files for strings rather quickly: it can be much easier to set up sets of files (search in files by file type, date, etc) using the graphical Find than the findstr command, and the results list is in an Explorer window, so you can easily open or otherwise manipulate file results in a familiar setting.

Deleting Files

If you want to delete files by extension across directories (great for housekeeping chores), try this command (which in this case would delete all BAK and TMP files):

Go To Page: 1 2


The copyright of the article Command Line Usage in Windows NT Workstation is owned by . Permission to republish Command Line Usage in print or online must be granted by the author in writing.

Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo