Showing posts with label Sort. Show all posts
Showing posts with label Sort. Show all posts

Tuesday, 15 September 2015

Using the FileSelectionManager library in Visual Basic

In previous posts, we presented samples of File Selection Manager using C#.

Here you can see the same projects, using Visual Basic instead of C#.

Download the projects here:

How to make an incremental backup
How to create an advanced file searcher
Sort a FileInfo Collection

Test the projects and give us your opinion.

Friday, 28 August 2015

Sort a FileInfo collection in C# like a database using FileSelectionManager

Adding the FileSelectionManager library to a project means you can select and sort files using pseudo-SQL sentences, like a database. In this article we focus on the sort feature.

First of all you have to download the FileSelectionManager library, then create a console application and add the library to your project as a new reference.

Next, write the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using FileSelectionManager;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            if(args.Count()!=2 || !Directory.Exists(args[0]))
                throw new ArgumentException("Invalid Parameters");
            else
            {
                //Selecting Files
                FSM fManager = new FSM();
                fManager.Dir(args[0], true, args[1]);

                //Show results
                Console.WriteLine("Files Affected: " + fManager.AffectedFiles);
                Console.WriteLine("Files Involved: " + fManager.InvolvedFiles);

                foreach (System.IO.FileInfo file in fManager.SelectedFiles)
                {
                    Console.WriteLine("Found: {0} - {1} - {2} - {3} ",
                    file.DirectoryName,
                    file.Name,
                    file.CreationTime,
                    file.Length);
                }
            }
        }
    }
}


Imagine you have the following directory and file structure:



Compile your application and execute it, giving it the directory, the select criteria and the sort clause.
Here are three examples: