This page's shorter URL is http://tinyurl.com./yslrz6.

Performing some commonly desired tasks with JP Software's command interpreters.

You've come to this page because you've asked how to perform one of several tasks that people seem to ask how to do again and again, such as:

These are the Frequently Given Answers to such questions, that use the command interpreters from JP Software.

Unless otherwise stated, these answers apply to (the most recent versions of) all of JP Software's command interpreters. So the same procedure will work with (for example) 4DOS, 4OS2, and 4NT.

How to obtain a list of all of the available built-in commands.

The simplest answer to

How do I obtain a list of all of the available built-in commands?

is:

Press the F1 key. The contents page of the command interpreter's on-line help, which pressing that key will invoke, lists all of the built-in commands. From there you can proceed to the help for each individual command.

There is another answer that is almost as simple:

Use the ? command. Simply invoke the command line

?

and you will be presented with a list of all built-in commands. Each of those commands will present a brief synopsis and argument summary when invoked with /? as its command tail.

How to include the current date and/or time in directory or file names.

There are a whole load of implicit environment variables that expand to various values. For example: %_MONTH% always expands to the current month number. These can be used in command lines and in scripts to insert various parts of the current date and time into commands.

For example, the answer to

How do I rename the file "something.txt" to include the current month and day in its name?

is a simple one-liner:

rename something.txt something-%_MONTH%-%_DAY%.txt

Similarly, the answer to

How do I create a directory whose name is the current date?

is a simple exercise in the use of the %_DATE% implicit environment variable:

mkdir %_date%

This will fail if your country's date format uses '/' as the date separator character, of course. But to solve this you can either simply add the %@replace[] function to the mix to change the separator character:

mkdir %@replace[/,-,%_date%]

or you can compose the date string yourself, from its component parts, with an appropriate separator character of your choosing:

mkdir %_year%!%_month%!%_day%

Using other dates is slightly more complex. The answer to

How do I create a directory whose name is yesterday's date?

involves using the %@makedate[], %@edate[], and %@eval[] functions as well as the %_DATE% implicit environment variable:

mkdir %@makedate[%@eval[%@date[%_date]-1]]

How to restrict processing of files and directories to only those with specific timestamps.

Most commonly people ask about deleting files:

How do I delete all files that were last modified 7 or more days ago?

This can be achieved in a single line, using the ordinary DEL command and simply supplying a date range option:

del /[d-7,%@makedate[0]] *

DEL is not the only command that supports date ranges. For example: One can move, copy, or rename files with similar restrictions by supplying date ranges to the MOVE, COPY, and RENAME commands. Read the command interpreter documentation for the full list of commands that support date ranges.

OS/2 and Win32 have the concepts of multiple, different, timestamps on files, not just a single "last modification" timestamp. With the native OS/2 and Win32 command interpreters, one can apply date ranges to these timestamps as well. One commonly desired task is to find out about file accesses:

How do I find out which files have been accessed within the last 7 days?

Again, this can be achieved in a single line, using the DIR command and a date range that operates upon the "last access" timestamps:

dir /[da-7] *

Similarly the answer to

How do I rename files that were created 14 or more days ago?

uses the RENAME command and a date range that operates upon the "creation" timestamps:

ren /[dc-14] *.txt *.txt.fortnight-or-more-old

How to read user input into an environment variable.

How do I read user input into an environment variable, so that I can then use it as an argument to further commands?

The built-in input command does exactly this:

input What file would you like to look at? %%NAME
more < %NAME%

One commonly desired task is to obtain user input without displaying it at the same time:

How do I read user input into an environment variable, for use as before, but without displaying what the user enters as it is typed?

input's /P option does exactly this:

input /p What is the password? %%PASSWORD
echo You typed %PASSWORD%.

© Copyright 2003,2007 Jonathan de Boyne Pollard. "Moral" rights asserted.
Permission is hereby granted to copy and to distribute this web page in its original, unmodified form as long as its last modification datestamp is preserved.