Пример #1
0
        public static int DeleteEmptyFile(ITaskItem[] filesToDelete)
        {
            if (filesToDelete == null)
            {
                return(0);
            }

            ITaskItem[] items = TrackedDependencies.ExpandWildcards(filesToDelete);
            if (items.Length == 0)
            {
                return(0);
            }

            int deleted = 0;

            foreach (ITaskItem item in items)
            {
                try {
                    var info = new FileInfo(item.ItemSpec);
                    if (info.Exists && info.Length <= 4)
                    {
                        info.Delete();
                        ++deleted;
                    }
                } catch (SecurityException) {
                } catch (ArgumentException) {
                } catch (UnauthorizedAccessException) {
                } catch (PathTooLongException) {
                } catch (NotSupportedException) {
                }
            }

            return(deleted);
        }
Пример #2
0
        protected static int DeleteEmptyFile(ITaskItem[] filesToDelete)
        {
            if (filesToDelete == null)
            {
                return(0);
            }
            ITaskItem[] taskItemArray = TrackedDependencies.ExpandWildcards(filesToDelete);
            if (taskItemArray.Length == 0)
            {
                return(0);
            }
            int num = 0;

            foreach (ITaskItem taskItem in taskItemArray)
            {
                bool flag = false;
                try
                {
                    FileInfo fileInfo = new FileInfo(taskItem.ItemSpec);
                    if (fileInfo.Exists)
                    {
                        if (fileInfo.Length <= 4L)
                        {
                            flag = true;
                        }
                        if (flag)
                        {
                            fileInfo.Delete();
                            ++num;
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (!(ex is SecurityException))
                    {
                        if (!(ex is ArgumentException))
                        {
                            if (!(ex is UnauthorizedAccessException))
                            {
                                if (!(ex is PathTooLongException))
                                {
                                    if (!(ex is NotSupportedException))
                                    {
                                        throw;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(num);
        }