0

I'm trying to identify whether the content inside a fileinfo object is a directory and if not I need to add them in a stack. I'm trying with the below code but getting the subjected error in the "IF condition" not sure how to proceed from here. Any help is much appreciated.

        public void Main()
        {
// below (dts.var[]) is an object value coming from SSIS storing the fileinfo details in object format {feel free to include a fileInfo object that has file/directory details from any local path}
            var fileinfo = Dts.Variables["User::SharePointListOfFiles"].Value; 
            List<String> OutputFileNames;
            string outputresultnames = "";
            int directory = 0; 

            foreach (object element in (fileinfo as IEnumerable ?? Enumerable.Empty<object>()))
            {
                var type = element.GetType();
                var props = type.GetProperties();

                foreach (var prop in props)
                {
                    if ( prop.Attributes.HasFlag(FileAttributes.Directory))

                    {
                        directory = 1;

                    }

                }

                if (directory == 0)
                {
                    object result = props.First().GetValue(element, null);
                    outputresultnames = (string)result;
                    OutputFileNames.Add(outputresultnames);

                }
            }
}
Gowtham Ramamoorthy
  • 896
  • 4
  • 15
  • 36
  • Didn't you [solve this yourself](https://stackoverflow.com/questions/61945475/read-an-object-variable-having-fileinfo-object-content-in-c-sharp-script-task)? – billinkc Jun 10 '20 at 18:36
  • Thanks... the original code part I solved it... but later got a new requirement to exclude objects that are "Directories/Folders" and I got stuck there. – Gowtham Ramamoorthy Jun 10 '20 at 18:47

0 Answers0