Here is some simple code:
DIR* pd = opendir(xxxx);
struct dirent *cur;
while (cur = readdir(pd)) puts(cur->d_name);
What I get is kind of messy: including dot (.
), dot-dot (..
) and file names that end with ~
.
I want to do exactly the same thing as the command ls
. How do I fix this, please?
The "ls" command has many options that, when passed, affect the output. For example, the "-a" option will show all files and folders, including hidden ones.
To show hidden files, you need to include the /a:h modifier in that command. So, dir /a:h C:your-folder will do the trick. CMD also has specific commands for showing directories and folders. /a:d shows all hidden directories, and /a shows hidden folders.
The dir command is a command close to the ls command on Linux : it displays directory contents on your system. Similarly to the ls command, it can be used in order to show hidden files in a directory.
This is normal. If you do ls -a
(which shows all files, ls -A
will show all files except for .
and ..
), you will see the same output.
.
is a link referring to the directory it is in: foo/bar/.
is the same thing is foo/bar
.
..
is a link referring to the parent directory of the directory it is in: foo/bar/..
is the same thing as foo
.
Any other files beginning with .
are hidden files (by convention, it is not really enforced by anything; this is different from Windows, where there is a real, official hidden attribute). Files ending with ~
are probably backup files created by your text editor (again, this is convention, these really could be anything).
If you don't want to show these types of files, you have to explicitly check for them and ignore them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With