[英]Why do dots (“.” and “..”) appear when I print files from directory?
I'm printing files from two directories using C language. 我正在使用C语言从两个目录中打印文件。 Here is my code:
这是我的代码:
char *list1[30], *list2[30];
int i=0, x=0;
struct dirent *ent, *ent1;
/* print all the files and directories within directory */
while ((ent = readdir (dirSource)) != NULL) {
list1[i] = ent->d_name;
i++;
}
i=0;
while((ent1 = readdir (dirDest)) != NULL) {
list2[i] = ent1->d_name;
i++;
}
while(x != i){
printf("Daemon - %s\n", list1[x]);
printf("Daemon1 - %s\n", list2[x]);
x++;
}
I can print all the files, but everytime I print the files in a directory, the end result is this: 我可以打印所有文件,但是每次我在目录中打印文件时,最终结果是这样的:
Daemon - . 守护程序-。 Daemon1 - .
守护程序1-。 Daemon - .. Daemon1 - .. Daemon - fich5 Daemon1 - fich4 Daemon - fich3 Daemon1 - fich3
Daemon-.. Daemon1-.. Daemon-fich5 Daemon1-fich4 Daemon-fich3 Daemon1-fich3
I don't understand why there are dots in the beginning. 我不明白为什么一开始会有点。 Obs.: I don't if it matters, but I'm using Ubuntu 14.04 on a pen, meaning every time I use Ubuntu, I use the trial instead of using dual boot on my pc.
观察:没关系,但是我在笔上使用Ubuntu 14.04,这意味着每次我使用Ubuntu时,我都使用试用版,而不是在PC上使用双启动。
.
and ..
are two special files which are in every directory in Linux and other Unix-like systems. 和
..
是两个特殊文件,它们位于Linux和其他类似Unix的系统的每个目录中。 .
represents the current directory and ..
represents the parent directory. 代表当前目录,而
..
代表父目录。
Every directory in Unix has the entry .
Unix中的每个目录都有该条目
.
(meaning current directory) and ..
(the parent directory). (表示当前目录)和
..
(父目录)。 Give that they start with "." 让他们以“。”开头。 they are hidden files;
它们是隐藏文件;
ls
normally do not show them unless you use "-a" option. ls
通常不会显示它们,除非您使用“ -a”选项。
See: 看到:
[:~/tmp/lilla/uff] % ls -l
total 0
-rw-rw-r-- 1 romano romano 0 May 17 18:48 a
-rw-rw-r-- 1 romano romano 0 May 17 18:48 b
[:~/tmp/lilla/uff] % ls -la
total 8
drwxrwxr-x 2 romano romano 4096 May 17 18:48 .
drwxrwxr-x 3 romano romano 4096 May 17 18:47 ..
-rw-rw-r-- 1 romano romano 0 May 17 18:48 a
-rw-rw-r-- 1 romano romano 0 May 17 18:48 b
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.