1

First of all, I want to notice that this may not be an Octave question itself (I really cannot tell), hopefully this will be clear by the end of the question.

I am running some Octave code to get a list of all files under a folder. The following line of code gives me an array of structs containing all file info in the folder C:/Whatever/

>> dirPath = "C:/Whatever/";
>> files = dir(dirPath); 

In practice I am dealing with a folder full of images, and my goal is to get the size of each of the images, but first I need to retrieve the names of the files to load each of them, and this seems a reasonable way to do so.

The surprise comes when I realise that my folder has 2547 files, but the array files has length 2549, i.e., Octave found two additional files. These are located at the first and second places of the array files, and their names are "." and "..", respectively. More precisely, when asking for the names of these files the following happens:

>> files(1).name
ans = .
>> files(2).name
ans = ..

Of course, in order to achieve my goal I could ignore this and start getting file info form the 3rd place of the array files. However this looks far from a clean solution to me, and I would like to understand what is happening or where do these two additional files come from. It is worth saying that I am working on a W10 system and that I have unabled hidden file visibility (so the possibility that these are hidden files is excluded), and that the folder is contained in some subfolder of my computer's Dropbox folder.

Thanks in advance.

Edit:

These two additional files appear to be folders. Also, there is a similar question provided in the comments:

MATLAB dir without '.' and '..'

That post has answers addressing the problem of eliminating the additional folders from your file list, but what I would really like is to know is what they are and why are they there.

  • 2
    Does this answer your question? [MATLAB dir without '.' and '..'](https://stackoverflow.com/questions/27337514/matlab-dir-without-and) – Cris Luengo Jan 17 '21 at 20:35
  • The dupe target is for MATLAB, not Octave, but in this case the solutions are identical. – Cris Luengo Jan 17 '21 at 20:37
  • The answers in that question are ok and show some workaround for the problem (as the one I mentioned for example), but I am more interested in knowing what are those folders and why are they there, thanks though! – Alberto Debernardi Jan 18 '21 at 10:04
  • 2
    Explaining . (this folder) and .. (subfolder) https://unix.stackexchange.com/questions/63081/what-are-and-directories/63087#63087 . the question is asked for Linux/Unix but the answer is valid for Windows as well – Nick J Jan 18 '21 at 12:52
  • Thank you very much, if you would like to write that as an answer I will mark it as accepted. – Alberto Debernardi Jan 19 '21 at 09:17

0 Answers0