Пример #1
0
        public void TestGetFilesWithSearchWithNoResults()
        {
            var files = Directory.GetFiles(longPathDirectory, "giberish").ToArray();

            Assert.AreEqual(0, files.Length);
            Assert.IsFalse(files.Contains(longPathFilename));
        }
Пример #2
0
        public void TestGetFilesWithSearch()
        {
            var files = Directory.GetFiles(longPathDirectory, "*").ToArray();

            Assert.AreEqual(1, files.Length);
            Assert.IsTrue(files.Contains(longPathFilename));
        }
Пример #3
0
        public async static void SwitchDirectory(DirectoryNode dir)
        {
            Globals.nrOfButtons = 0;
            foreach (var button in buttons)
            {
                button.delete = true;
            }
            DirectoryNode tempDirectory = null;

            foreach (var node in nodeTree)
            {
                if (node.path == dir.path)
                {
                    tempDirectory = node;
                }
            }                                                                                        //replace with hash table?
            if (tempDirectory == null)
            {
                nodeTree        = new List <DirectoryNode>();
                Globals.topNode = new DirectoryNode(null, dir.path, false);
                await GenerateNodeTreeAsync(dir.path, Globals.topNode);   //async?

                SwitchDirectory(dir);
                return;
            }
            Globals.currentNode = tempDirectory;
            foreach (var child in tempDirectory.children)
            {
                if (!child.file)
                {
                    buttons.Add(new DirectoryButton(child.path, child));
                }
            }
            string[] files = Directory.GetFiles(dir.path, "*.*", System.IO.SearchOption.TopDirectoryOnly);
            foreach (var file in files)
            {
                buttons.Add(new Button(file, tempDirectory.getChild(file)));
            }
            Globals.scrollMax = -Globals.nrOfButtons * 32;
            sb.swPos          = 40;
            Globals.offset.Y  = 0;
        }
Пример #4
0
        public void TestGetRecursiveFilesWithAnySearch()
        {
            var tempLongPathFilename = longPathDirectory.Combine(Pri.LongPath.Path.GetRandomFileName());

            tempLongPathFilename.CreateDirectory();

            try {
                Assert.IsTrue(tempLongPathFilename.Exists());
                var randomFileName = Util.CreateNewEmptyFile(tempLongPathFilename);

                var files = Directory.GetFiles(longPathDirectory, "*", SearchOption.AllDirectories).ToArray();
                Assert.AreEqual(2, files.Length);
                Assert.IsTrue(files.Contains(longPathFilename));
                Assert.IsTrue(files.Contains(randomFileName));
            }
            finally {
                const Boolean recursive = true;
                Directory.Delete(tempLongPathFilename, recursive);
            }
        }
Пример #5
0
        static DirectoryNode GenerateNodeTree(string dir, DirectoryNode parent)
        {
            Globals.curDir = dir;
            DirectoryNode newNode = new DirectoryNode(parent, dir, false);

            try
            {
                string[]             files    = Directory.GetFiles(dir, "*.*");
                long                 size     = 0;
                List <DirectoryNode> children = new List <DirectoryNode>();
                foreach (string name in files)
                {
                    FileInfo info = new FileInfo(name);
                    size += info.Length;
                    DirectoryNode tempFileNode = new DirectoryNode(newNode, name, true)
                    {
                        size = info.Length
                    };
                    nodeTree.Add(tempFileNode);
                    children.Add(tempFileNode);
                }
                string[] c = Directory.GetDirectories(dir, "*.*");
                Globals.curAllDir += c.Length;
                foreach (string name in c)
                {
                    DirectoryNode tempNode = GenerateNodeTree(name, newNode);
                    size += tempNode.size;
                    children.Add(tempNode);
                }
                newNode.size     = size;
                newNode.children = children;
                nodeTree.Add(newNode);
                Globals.curDoneDir++;
            }
            catch
            {
                newNode.size   = 0;
                newNode.locked = true;
            }
            return(newNode);
        }
Пример #6
0
        public void TestGetRecursiveFilesWithSubsetSearch()
        {
            var tempLongPathFilename = longPathDirectory.Combine(Pri.LongPath.Path.GetRandomFileName());

            tempLongPathFilename.CreateDirectory();

            try {
                Assert.IsTrue(tempLongPathFilename.Exists());
                var randomFileName = Util.CreateNewEmptyFile(tempLongPathFilename);

                var searchPattern = randomFileName.GetFileName().Substring(0, 3) + "*" + randomFileName.GetExtension();

                var files = Directory.GetFiles(longPathDirectory, searchPattern, SearchOption.AllDirectories).ToArray();
                Assert.AreEqual(1, files.Length);
                Assert.IsFalse(files.Contains(longPathFilename));
                Assert.IsTrue(files.Contains(randomFileName));
            }
            finally {
                const Boolean recursive = true;
                Directory.Delete(tempLongPathFilename, recursive);
            }
        }