This project is read-only.

Fileinfo - FileNotFoundException

Jun 25, 2014 at 6:54 PM
My project includes a method, which walks through all files/folders in a given DirectoryInfo, obtaining the file size, in order to return the total size of all files in the given folder. My first attempt of course, was to use the System.IO methods, which resulted in pathtoolong - hence the reason I tried AlphaFS.

Unfortunately, for some - yet unknown reason, I keep getting FileNotFoundException. Relevant code follows:
long total = 0;
List<long> dsizes = new List<long>();
Alphaleonis.Win32.Filesystem.DirectoryInfo rootInfo = new Alphaleonis.Win32.Filesystem.DirectoryInfo(@"E:\");
Alphaleonis.Win32.Filesystem.DirectoryInfo[] dis = rootInfo.GetDirectories();
foreach (Alphaleonis.Win32.Filesystem.DirectoryInfo di in dis)
{
            long size = DirSize(di);
            dsizes.Add(size);
            total += size;
}

public static long DirSize(Alphaleonis.Win32.Filesystem.DirectoryInfo d)
{
        long Size = 0;
        // Add file sizes.
        Alphaleonis.Win32.Filesystem.FileInfo[] fis;
        try
        {
                fis = d.GetFiles();
        }
        catch (System.UnauthorizedAccessException)
        {
                fis = new Alphaleonis.Win32.Filesystem.FileInfo[0];
        }
        foreach (Alphaleonis.Win32.Filesystem.FileInfo fi in fis)
        {
                try
                {
                        Size += fi.Length;
                }catch(System.IO.FileNotFoundException)
                {
                        Debug.WriteLine(fi.FullName);
                        Debug.WriteLine(fi.Exists);
                        Size += 0;
                }
        }
}
Debug Output shows:
E:\Windows.old\Users\All Users\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Adobe\CameraRaw\LensProfiles\1.0\Tokina\Nikon\NIKON CORPORATION (Tokina AT-X 165 PRO DX 16-50mm F2.8 (IF) ASPHERICAL) - RAW.lcp
False
Yet, copying and pasting that path into Windows Explorer, will give me the open with window, and of course, just pasting the path will give me the folder.
Developer
Jun 26, 2014 at 7:32 AM
Hi,

Which Windows version are you testing this on?

If I'm corrected that would be a Junction point, causing endless recursion when enumerating.

Yomodo
Jun 26, 2014 at 5:03 PM
Windows 8.1 - targeting .Net 4.5.

To the best of my knowledge there were no junctions involved , and it seems that the library was functioning fine with enumerations, otherwise (correct me if I'm wrong) it wouldn't have gotten so deep in the tree. I mean, it walked over everything - it just failed when it attempted to check if it existed or not.

For the time being anyway, I just got around it by simply going through explorer, reducing the length of the folder names until I could delete them, and just (finally) got rid of that whole Windows.old folder.

Though, I am curious why the exists check failed.