Episode: 3640
Title: HPR3640: Expert DIR use
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr3640/hpr3640.mp3
Transcribed: 2025-10-25 02:37:22

---

This is Hacker Public Radio Episode 3,640 for Friday the 15th of July 2022.
Today's show is entitled, Expert Diary Use.
It is part of the series' DOS.
It is hosted by Okka, and is about 15 minutes long.
It carries a clean flag.
The summary is.
We continue with DOS.
This time, it is mastering the DIR commands.
Hello, this is Hacker, welcome to the Hacker Public Radio, and another exciting episode
in our DOS series, and we're going to look at really stepping up our game on using
the DIR command.
So we had looked at some of the commands used to manipulate directories in a previous
one, and then at the last time we looked at wildcards and file attributes, and we're
going to be able to put all these pieces together and learn how to use the DIR command like
an expert.
So the first we can use the DIR with wildcards.
So the DIR command is generally used to get a listing of all the files in a given
subdirectory, but it can do more.
If the DIR command is given without any arguments, it returns a list of all the files in the
subdirectory.
But with a few arguments, it becomes a search tool that is very useful.
For instance, you can use wildcards to search for a file that matches certain characters,
right?
Let's say you wanted to see all the documents.
Well, at the prompt, you could type DIRspaceStar.doc.
Now this command would return a list of all files in the root directory that have the
DOC extension.
So assuming that you use the DOC extension for all of your document files, you would
have to do that for this to work.
This would be a very good way of just seeing all of them with the DIR command without seeing
all of the other files that might exist in that directory.
Now here's another example.
At the prompt, DIRspace, memo, MEMO, question mark, period, asterisk.
This command would return a list of all files in the directory that have names that begin
with MEMO and have one additional character following in the name and have any extension
at all.
So you can use all of the DOS wildcards we discussed in the previous lesson to find specific files.
This can be very handy in a large directory to check for files or to make sure before
using a DEL command with wildcards that you know exactly what you are deleting.
Remember that DOS does not have a recycle bin.
So when you delete a file, it may very well be unrecoverable.
There are utilities that we've had for a long time in DOS to allow you to undelete a file.
They are rather uncertain.
You better not to make the mistake in the first place.
The way they work is that when DOS deletes a file, what it does is it deletes the first
character of the file name and then it says it takes the sectors on the drive that held
that file and says those are now available for use.
So what the undelete commands would do is they would look for ones that had the first
character missing and bring those up and then if you could spot your file, you could
recover it.
But remember, those sectors were marked available for use.
So if you caught it right away, excellent chance you could recover your file.
If you didn't notice it until a week later, you might well have saved something else
onto those sectors and that data is now gone forever.
So you did want to be careful about all of this.
Now you can also use the DIR command with an attribute argument to find files that match
the attribute selected.
The syntax for this is the DIR command followed by a space, then slash A, which signals an
attribute argument, followed by the specific attribute you want to find.
So here's how it would work.
Now there's 10 attributes you can specify, H for hidden, minus H for not hidden, S for
system, minus S for not system, A for archivable, minus A for already archived, R for read only,
minus R, not read only, in other words, editable and deletable files, D, directories only, no
files, or minus D, files only, no directories.
Yeah, so you want to do this.
You want to find all the files you have not yet backed up.
Well, let's take this a step at a time.
In your present working directory, I'm assuming that's where you're going to be searching,
you'd use a command like this, DIR space, forward slash A, colon, and forward slash A, colon
says I'm about to stick in an attribute argument here, and then you type another A, and that
says archivable, archivable beats that hasn't been backed up yet.
So that command would go through the present working directory and locate every file
that has not been backed up.
So every file in the directory with the archive bit set on would be returned by the command.
Now suppose we did a command, let's say we went into our docs directory, C colon, backslash,
docs, backslash, greater than, that's our prompt, that's telling us the prompt is telling
us the present working directory.
And then command, DIR space slash A, colon, that's the thing that says I'm about to use an
archive argument.
I've been an attribute argument here, minus A, that's going to look for things that are
already archived, R. So DIR space, forward slash A, colon,
minus A, R. This would return every file in the docs sub directory that was read only
and already backed up.
Now if you know about Boolean operators, what happens when you use multiple attributes
is that the command is interpreted as a logical and command, which means that every file
returned has to satisfy all of the attribute specifications.
Now let's say we're in the temp directory, C colon, backslash, temp, backslash, greater
than, that's our prompt, DIR space, forward slash A, colon, H. This would return every file
in the C temp directory that was marked hidden.
Now interestingly, if you used a simple DIR command, no hidden files would be displayed,
but when you use this command, they're just played for you quite plainly.
So in other words, marking a file is hidden in DOS is not a lot of security.
In other words, don't rely on it that way.
The real purpose of doing this is not so much to give you a high level of security as to
stop you from shooting yourself in the foot, all right?
When you mark a file as hidden in DOS, it's hidden to other commands.
So in other words, a DEL space star dot star would not delete a hidden file.
Now, hidden files may contain stuff that you really don't want to have accidentally
deleted, and that's what it's for.
But you know, you can always turn it on.
I noted that later on with Windows, it changed slightly.
You could go into the Windows Explorer and say, I want to show hidden files, and it would
pop up a message saying, are you sure you know what you're doing?
But it would do it.
Now, sometimes particularly in the root directory, you may need to look for sub-directories you
have established.
If you use a simple DIR command, you'll be presented with several screens of files and sub-directories
all mixed up.
But you can do this.
D colon backslash greater than, so that's my prompt.
I'm at the root of the C drive.
I could do DIR space forward slash a colon that says I'm about to use an attribute in
a D. Now, this command will return only the sub-directories from the root directory without displaying
any of the files.
Now you can also put things in order, okay?
This syntax for this is very similar to using attributes.
You leave a space after the DIR command or after any other switches and enter forward slash
O colon, followed by a selection to put things in order.
Here you have 12 possible options.
N is to put in alphabetical order by file name.
Minus N is reverse alphabetical order by file name.
E is alphabetical order by file extension.
Minus E reverse alphabetical order by file extension.
D is order by date and time earliest first.
Minus D order by date and time latest first.
S by size increasing.
Minus S by size decreasing.
C by double space compression ratio lowest to highest in that's inversion 6.0 of
DOS.
Double space was a disc compression algorithm that was very popular because as I've said,
in those days storage space was at a premium.
So compressing things was really a big deal.
Minus C is by double space compression ratio highest to lowest.
G is to group directories before other files and minus G group directories after other files.
So if you wanted to see your directory results grouped by file extension, you might want
to try something like this at the prompt type DIR space forward slash O colon E.
This will return a list of files put in alphabetical order of file extension.
So all of the DOC files will come before all of the EXE files and they will come before
all of the TXT files.
But if you're looking for that file you were working on yesterday, something like this
at the prompt DIR space forward slash O colon minus D. This will return a list of files
with the most recent ones at the top of the list.
Now, if you need to clean up your hard drive because you're running out of space you might
want to know which ones are the largest.
So at the prompt type DIR space forward slash O colon minus S. This will return a list
of files with the largest ones at the top of the list.
Now you can combine all of this in multiple arguments in the DIR command to achieve fairly
compact, complex results.
Remember that each argument has to be separated from its neighbors by a blank space on each
side.
So here's a good one.
At the prompt DIR space forward slash A colon A space forward slash O colon D space forward
slash P.
Well, that will select only those files that have not yet been backed up.
That was the A colon A argument.
Play them in order by date, that is the O colon D argument.
And display the result on your monitor one page at a time, and that's the P argument.
So you can really do some slick stuff with the DIR command once you've mastered the use
of these arguments and switches.
In case you were wondering anything that modifies a command is called an argument.
If it has a slash in front, it's a switch.
So all switches are also arguments, but some arguments such as path are not switches.
So try a few of these, and the best way to get comfortable with these commands of course
is to practice them.
So this is Ahuka for Hacker Public Radio signing off, and as always encouraging you to support
free software.
Bye bye.
You have been listening to Hacker Public Radio, as Hacker Public Radio does work.
Today's show was contributed by a HBR listener like yourself.
If you ever thought of recording podcasts, you click on our contribute link to find out
how easy it really is.
Hosting for HBR has been kindly provided by Anonsthost.com, the Internet Archive, and
R-Sync.net.
On the Sledoise status, today's show is released under Creative Commons, Attribution, 4.0 International
