public static bool DeleteDirectory(string fullPath, bool recursive)
        {
            if (recursive)
            {
                var allOk = true;
                foreach (var n in SccFileSystemNode.GetDirectoryNodes(fullPath))
                {
                    if (n.IsDirectory)
                    {
                        if (!DeleteDirectory(n.FullPath, true))
                        {
                            allOk = false;
                        }
                    }
                    else if (!DeleteFile(n.FullPath))
                    {
                        allOk = false;
                    }
                }
                if (!allOk)
                {
                    return(false);
                }
            }

            return(DeleteDirectory(fullPath));
        }
예제 #2
0
        static IEnumerable <SccFileSystemNode> DoGetDirectoryNodes(SccFileSystemNode result, SafeFindHandle findHandle)
        {
            var basePath = result._basePath;

            using (findHandle)
            {
                if (!IsDotPath(result.Name))
                {
                    yield return(result);
                }

                NativeMethods.WIN32_FIND_DATA data;
                while (NativeMethods.FindNextFileW(findHandle, out data))
                {
                    if (IsDotPath(data.cFileName))
                    {
                        continue;
                    }

                    yield return(new SccFileSystemNode(basePath, data.cFileName, (FileAttributes)data.dwFileAttributes));
                }
            }
        }