Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

"." and ".."

Posted on 2011-03-03
10
207 Views
Last Modified: 2012-05-11
Hi,
 I need explanation of "." and ".." value in d_name of struct direct when reading directory in Linux . Thanks a lot.
0
Comment
Question by:BeginToLearn
  • 5
  • 4
10 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35034183
"." refers to the current directory itself,
".." refers to the parent directory
0
 

Author Comment

by:BeginToLearn
ID: 35034192
about DT_DIR? could you explan this
 
 if ( DT_DIR & pEntry->d_type && strcmp ( pEntry->d_name, ".") && strcmp ( pEntry->d_name, ".."))

 tks.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35034206
this condition checks IF the pEntry->d_name value is either "." or ".." , and if the p_entry.d_type is DT_DIR ...
presumable to exclude those from the processing ...
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:BeginToLearn
ID: 35034216
i now what it check. but i don't understand the meaning of "." and ".." in this case which is reading directory. thanks.
0
 

Author Comment

by:BeginToLearn
ID: 35034222
i mean relate to

"." refers to the current directory itself,
".." refers to the parent directory

can u give example?
tks
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 450 total points
ID: 35034279
see this "copy/paste" from my dos box:
C:\WINNT>dir
 Volume in drive C is OSDisk
 Volume Serial Number is FC2D-08F6

 Directory of C:\WINNT

03/03/2011  15:44    <DIR>          .
03/03/2011  15:44    <DIR>          ..
03/01/2011  08:17                 0 0.log
10/07/2008  20:58    <DIR>          addins
21/04/2009  13:21    <DIR>          AppPatch
21/01/2008  14:48            12.477 atiogl.xml

Open in new window


so, the "current directory" is the one where you issue the "dir" command from (resp your C function ...)
 Directory of C:\WINNT

Open in new window

the "." refers to that same directly.
and ".." refers to "C:\"  

hope this clarifies
0
 

Author Comment

by:BeginToLearn
ID: 35034319
I understand "." now. It tell where the "dir " command is issued. But why do we need ".."?
any when a program copy a directory ( and its suddirectory ) to another place, do we need to skip "." and ".."? tks.
0
 
LVL 33

Assisted Solution

by:sarabande
sarabande earned 50 total points
ID: 35034415
we don't need the ".." but have to consider it when doing a directory listing and want to use only files or only sub directories.

Sara

0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 450 total points
ID: 35034432
"." and ".." are only logical links, and you cannot "copy" them. they are "created" automatically by the underyling file system.
you just skip them in any processing, the only thing you can do with it is to show them

having ".." means you have a parent folder, if you have no such item in the list, you cannot "go up" one folder.
0
 

Author Comment

by:BeginToLearn
ID: 35034441
tks all. I get it now.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question