Example #1
0
        /// <summary>
        /// Get files using an extended pattern with the option of wildcard
        /// characters in each path component.
        /// </summary>
        /// <param name="baseDir">A DirectoryInfo from which the matching starts</param>
        /// <param name="pattern">The pattern to match</param>
        /// <returns>A list of FileInfos</returns>
        public static IList <FileInfo> GetFiles(DirectoryInfo baseDir, string pattern)
        {
            // If there is no directory path in pattern, delegate to DirectoryInfo
            int lastSep = pattern.LastIndexOf('/');

            if (lastSep < 0) // Simple file name entry, no path
            {
                return(baseDir.GetFiles(pattern));
            }

            // Otherwise split pattern into two parts around last separator
            var pattern1 = pattern.Substring(0, lastSep);
            var pattern2 = pattern.Substring(lastSep + 1);

            var fileList = new List <FileInfo>();

            foreach (var dir in DirectoryFinder.GetDirectories(baseDir, pattern1))
            {
                fileList.AddRange(dir.GetFiles(pattern2));
            }

            return(fileList);
        }
        // TODO: These tests are fragile because they rely on the directory structure
        // of the project itself - we should find a better way to test.

        //[TestCase("addins", 1)]
        //[TestCase("net-*", 4)]
        //[TestCase("*/v2-tests", 1)]
        //[TestCase("add*/v?-*", 1)]
        //[TestCase("**/v2-tests", 1)]
        //[TestCase("addins/**", 2)]
        //[TestCase("addins/../net-*", 4)]
        //[TestCase("addins/v2-tests/", 1)]
        //[TestCase("addins//v2-tests/", 1)]
        //[TestCase("addins/./v2-tests/", 1)]
        public void GetDirectories(string pattern, int count)
        {
            var dirList = DirectoryFinder.GetDirectories(_baseDir, pattern);

            Assert.That(dirList.Count, Is.EqualTo(count));
        }