Saturday, May 17, 2014

Code Snippet - To retrieve file information in any given folder

public void Main()
              {
                     // TODO: Add your code here
            string curpath = string.Empty;

            //Add your folder path 
            curpath = @"C:\XYZ\ABC";
 
            DirectoryInfo dirinfo = new DirectoryInfo(curpath);

            //Add your file types eg.*.txt, *.doc
            FileInfo[] Files = dirinfo.GetFiles("*.dtsx");

            string str = string.Empty;
            string str_fl_crdt = string.Empty;
            //string str_fl_accsdt = string.Empty;
            string str_fl_updt = string.Empty;
 
            foreach (FileInfo file in Files)
            {
                 str = str + ", " + file.Name;
 
                 str_fl_crdt = file.CreationTime.ToString();
                 str_fl_accsdt = file.LastAccessTime.ToString();
                 str_fl_updt = file.LastWriteTime.ToString();
            }
 
                     Dts.TaskResult = (int)ScriptResults.Success;
              }