Exemplo n.º 1
0
        public void ScanItem()
        {
            IntPtr arrayValue        = IntPtr.Zero;
            IntPtr arrayValueInitial = IntPtr.Zero;
            Int32  count;
            Int32  itemSize;

            PInvoke.WIN32_FIND_DATA data;

            count = ScanDirectory(DirectoryNat.MakeUniversalPath(root.basePath + relPath + "*"), out arrayValueInitial);
            if (count == -1)
            {
                throw new Exception("First filefind failed");
            }
            arrayValue = arrayValueInitial;

            itemSize = Marshal.SizeOf(typeof(PInvoke.WIN32_FIND_DATA));
            for (int item = 0; item < count; item++)
            {
                DateTime creationTime;
                DateTime lastWriteTime;

                data = (PInvoke.WIN32_FIND_DATA)Marshal.PtrToStructure(arrayValue, typeof(PInvoke.WIN32_FIND_DATA));

                creationTime  = DateTime.FromFileTimeUtc((((Int64)data.ftLastAccessTime.dwHighDateTime) << 32) + (Int64)data.ftLastAccessTime.dwLowDateTime);
                lastWriteTime = DateTime.FromFileTimeUtc((((Int64)data.ftLastWriteTime.dwHighDateTime) << 32) + (Int64)data.ftLastWriteTime.dwLowDateTime);

                if ((data.dwFileAttributes & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory)
                {
                    if (data.cFileName != "." && data.cFileName != "..")
                    {
                        if (childs == null)
                        {
                            childs = new List <FileInfo>();
                        }
                        childs.Add(new FileInfo(this, data.cFileName, creationTime));
                    }
                }
                else
                {
                    if (files == null)
                    {
                        files = new List <FileInfo>();
                    }
                    files.Add(new FileInfo(this, data.cFileName, creationTime, lastWriteTime, data.dwFileAttributes, ((Int64)data.nFileSizeHigh << 32) | data.nFileSizeLow));
                }

                arrayValue = new IntPtr(arrayValue.ToInt64() + itemSize);
            }

            ScanDirectoryFree(arrayValueInitial);
        }
Exemplo n.º 2
0
        public void ScanItemN()
        {
            FileFindNat find = new FileFindNat(DirectoryNat.MakeUniversalPath(root.basePath + relPath + "*"));
            bool        findOK;

            findOK = find.Next();
            // Error if not found on first item
            if (!findOK)
            {
                throw new Exception("First filefind failed");
            }

            while (findOK)
            {
                if (find.IsDirectory)
                {
                    if (find.Name != "." && find.Name != "..")
                    {
                        if (childs == null)
                        {
                            childs = new List <FileInfo>();
                        }
                        childs.Add(new FileInfo(this, find.Name, find.CreationTimeUtc));
                    }
                }
                else
                {
                    if (files == null)
                    {
                        files = new List <FileInfo>();
                    }
                    files.Add(new FileInfo(this, find.Name, find.CreationTimeUtc, find.LastWriteTimeUtc, find.Attributes, find.Length));
                }

                findOK = find.Next();
            }
            find.Dispose();
        }