I have the following code to rename files in the following tree as from *00000001.pdf* to the last file with this 8 character left padding, e.g: *00000100.pdf*

1. Folder1
	* subfolder1
		1. childfolder1
			+ pdffile1
			+ pdffile2
		2. childfolder2
			+ pdffile3
			+ pdffile4
	* subfolder2
		1. childfolder3
			+ pdffile5
			+ pdffile6

But for some reason in some of those child folders it keeps renaming them with no end.
Some times it just jumps to another number, as if it was an async operation. But if I stop and start again it goes okay until the second next folder, when it messes up again.
But this error only happened within 19 folders.
Indeed their pdf names are different from the others, but I don't see how it is related.
The other files were named something like *"DOCUMENT\_01"* and so on, but these are:
*0000000100000001.pdf
0000000200000001.pdf
0000000300000001.pdf*
etc

```
static void Main(string[] args)
        {
            Console.WriteLine("Digite a pasta 'pai' onde serão buscados pdfs dentro das pastas 'filhas':");
            string path = Console.ReadLine();
            foreach (string dir in Directory.EnumerateDirectories(path))
            {

                foreach (string subdir in Directory.EnumerateDirectories(dir))
                {
                    Console.WriteLine($"{dir} - {subdir}");
                    int n = 1;
                    foreach (string pdffile in Directory.EnumerateFiles(subdir, "*.pdf", SearchOption.AllDirectories))
                    {                                  
                        Console.WriteLine(n.ToString().PadLeft(8, '0') + "  " + new FileInfo(pdffile).Length);
                        File.Move(pdffile, subdir + $"\\{n.ToString().PadLeft(8, '0')}.pdf");
                        n++;

                    }
                    Console.WriteLine("\n\n");
                }
            }
        }

```

What could be going wrong?
It should await for the File.Move method to end to add the n + 1 and then moving to the next pdffile as a synchronous operation. So why does it jumps numbers after a random time and why it keeps going forever other times?
And just to remember, if I stop the program and start again and put the folder that was messed up as the first one, it goes ok and only when it goes to the next folder, or the folder after next that it start to give me this error again.

Hope that I could make myself clear... Thanks for your attention!

EDIT: will try using FileInfo class to give me the parent folder with the SearchOption.AllDirectories option and exclude this 3 stage loop plus actually working for any kind of tree structure
EDIT2: Tried, worked as a "tree indepent" script but getting the same result with the files name after the first folder... As it's really fast, in 3 seconds it goes from *00000169.pdf* to *00006239.pdf* in a folder with just 330 items.