What "." and ".." in the Windows directory?

I am writing a program to list all the files in a directory in Windows. I just use these file management functions, but I wonder how the result is:

Target file is *.* The first file found is . The next file found is .. The next file found is file0 The next file found is file1 ... ... The next file found is fileN 

So technically, what is that "." and ".."? I remembered that I was using "cd .." in cmd to go to the top directory. For "cd." I do not know what this is for.

+4
source share
3 answers

"" is the current directory.

".." is the parent directory.

This is the same as Unix systems. From your output, it looks like Windows treats them as files.

In the past, I used "." so that the command (whatever it is) finds the file in the current directory. The following two statements must be identical:

 run some.exe run ./some.exe 

but if you have some weird search rules that first look at PATH or in C: \ Windows (for example), then that is not the case.

I found the following statements:

  • Use the period as a component of the directory in the path to represent the current directory, for example, ". \ Temp.txt". See the Outlines section for more information.
  • Use two consecutive periods (..) as a directory component in the path to represent the parent of the current directory, for example, ".. \ temp.txt". See the Outlines section for more information.

on the MSDN page Naming files, paths, and namespaces , but there is no explanation for what they really are.

The Wikipedia page on the Way is like a bit more information, but again does not explain how they are actually stored.

+8
source

A single point represents the current working directory. The double dot represents the current parent directory of the working directory.

None of them represents a specific β€œfile” in the underlying file system, but represents the location of the directory in the file system hierarchy. Although you have not mentioned this, the symbol "/" in itself is similar to the fact that it usually represents the root of a particular file system. i.e

 cd / 

will bring you to the root of the current file system.

Rather, '.' and ".." are links to available resources in the file system and, as such, are pseudo files or pseudo-links generated by a request for file information in the base file system and are included to aid in navigating around the file system. They are usually OS independent, i.e. most OS systems respect their use.

You say that you are "writing a program." Many file management routines that retrieve directory lists include a switch or a method that ignores these pseudo files when creating directory lists.

However, as a rule, it is easiest to write your own program to iterate over entries and ignore these entries in directories if you do not need them. Alternatively, write your program only for a list of files or even files of a particular type that you are looking for. For example, use commands such as DOS on Windows by running

 dir /a:-d 

will only show files in the directory, but not '.' and "..". while

 dir *.txt 

will list only .txt files in the directory.

+1
source

as mentioned above, ". represents the current directory. Although" .. "represents the parent directory. Windows presents them as links.

By the way, if ur is in the root directory, then Windows (cmd command line mode) considers '.' and ".." as one and the same.

Of course, in Windows Explorer the following do not stand up. there, if you go to the parent directory, say, C: \, then go to my computer.

0
source

Source: https://habr.com/ru/post/1340431/


All Articles