the purpose of directories "." and ".."

Started by
3 comments, last by FrigidHelix 23 years, 5 months ago
I recently had to use the Windows FindFirstFile/FindNextFile functions, and I noticed that directories "." and ".." kept appearing. What is the point of having these show up in the search? From what I understand (and this may be misinformation), these directories are simply the ones ''beneath'' the current one. I don''t see how this would be used in practice, can anyone explain their function to me, and inform me if I am somehow making a mistake by omitting them. Thanks.
Advertisement
. refers to the current directory. In some shells, you use it to refer to a program in the current directory (./myprogram).

.. refers to the directory underneath the current directory. This is good if you want to start a program that is in the directory beneath your current directory without having to type in the full path (../myprogram2).

Those are just two examples, I''m sure there are more...
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
cd .. means change directory to the parent of the directory you are in. So, .. is the parent directory.

_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
I also believe that a big reason for . is a holdover from UNIX. I could be wrong about this, but I BELIEVE that UNIX will look through your path before running a program from the current directory. So, if you are trying to run an executable called ''test'' but there is also an executable called ''test'' in the /etc/bin directory (or somewhere else in your path), you will end up running this other executable. If you want to run the one in the current directory, you just put ./test and you are sure that you are running the correct one.

Now, I could be wrong about this. I''m not a UNIX guru, but I believe that is how it works.
Yeah, that''s how most UNIX shells behave. But it is of course possible to program a new shell which behaves like DOS'' command.com... Or simply put ./ before everything else in your PATH and voíla.
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall

This topic is closed to new replies.

Advertisement