Saturday, May 4, 2013

Write a program to organize files in a folder (C#)

Hi, This is a program to organize files in a folder by type. You can do this for file size ,last access time or any other attribute as your wish. This program select a specific type of files among all files in a folder and create a  sub folder for the type and copy all the files of that type to the created folder. Try this.


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

namespace imagecoppy
{
    class Program
    {
        static void Main(string[] args)
        {
            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(@"C:\Users\Monto\Pictures");
            di.CreateSubdirectory("JPJs");

            System.IO.FileInfo[] fileNames = di.GetFiles("*.png*");
            foreach (System.IO.FileInfo fi in fileNames)
            {
                Console.WriteLine("{0}: {1}: {2}", fi.Name, fi.LastAccessTime, fi.Length);
                fi.CopyTo(@"C:\Users\Monto\Pictures\JPJs\"+fi.Name,false);
            }

            Console.ReadKey();
        }
    }
}

Look at some java codes of parallel programs http://tjisblogging.blogspot.com/

No comments:

Post a Comment