System :: IO :: Directory :: GetDirectories ("c: vs c: \\")

Just be curious

I had a problem that I used System::IO::Directory::GetDirectories("c:") instead of System::IO::Directory::GetDirectories("c:\\") .

This led to the extraction of directories from "C:\Windows\System32" . If I hadn't used backslashes with other drives, I finished the width directories, I did not know that they exist.

Can someone tell me why this is happening? Is there a sample? When is it used?

+4
source share
1 answer

When you omit the backslash at the beginning of a path (or after a drive letter), the path is considered relative to the current directory. You can get the value of the current directory using the System::IO::Directory::GetCurrentDirectory() method, and you can change it using the System::IO::Directory::SetCurrentDirectory(path) method.

To clarify this, note: if the current directory is C:\Windows , the path C:test.txt equivalent to C:\Windows\test.txt .

GetDirectories method returns all directories in the specified path, even hidden or system directories (which you usually do not see in Windows Explorer). Therefore, I think you are talking about system directories in other drives, such as System Volume Information and $RECYCLE.BIN .

It’s good to note that in the Windows shell (cmd.exe) we can have separate current directories for each drive. At startup:

 C:\Windows\System32> cd d:\Temp C:\Windows\System32> dir c: 

you get the contents of C:\Windows\System32 , and then at startup:

 C:\Windows\System32> dir d: 

you get the contents of D:\Temp

+4
source

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


All Articles