Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are "." and ".." in Windows' directory?

I am writing a program to list out all files in a directory on Windows. I simply use those File Management functions provided but I am curious about the result:

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 are these "." and ".." ? I recalled I use "cd .." in cmd to exit to the upper directory. For "cd .", I don't know what is it for.

like image 334
Karl Avatar asked Jan 21 '23 10:01

Karl


1 Answers

"." is the current directory.

".." is the parent directory.

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

In the past I've used the "." to make sure that the command (what ever it might be) finds the file in the current directory. The following two statements should be identical:

run some.exe

run ./some.exe

but if you have some weird search rules that looks on the PATH or in C:\Windows first (for example) then they aren't.

I've found these statements:

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

on the MSDN page on Naming Files, Paths, and Namespaces but there's no explanation of what they actually are.

The Wikipedia page on Path as a little more information, but again doesn't explain how these are actually stored.

like image 159
ChrisF Avatar answered Jan 27 '23 19:01

ChrisF