RePost: Help to convert a code to D

Andre Artus andre.artus at gmail.com
Mon Aug 26 13:14:32 PDT 2013


On Monday, 26 August 2013 at 13:30:38 UTC, Alexandre wrote:
> Hi :)
>
> I'm starting with D language... and, I try to convert a C# code
> to D...
> So, my C# code, I get file informations, and, I create folders
> with all days of month of specific year...
>
> So, that is my C# code...
>
> using System;
> using System.IO;
> using System.Linq;
> using System.Collections.Generic;
>
> namespace Organizador
> {
>      class Organiza
>      {
>          private string[] MesesDoAno =
>          {
>            "Janeiro", "Fevereiro",
>            "Marco", "Abril",
>            "Maio", "Junho",
>            "Julho", "Agosto",
>            "Setembro", "Outubro",
>            "Novembro", "Dezembro"
>          };
>
>          private string DirReceb = string.Empty;
>
>          public Organiza()
>          {
>              CriaDiretorios();
>              MoveArquivos();
>          }
>
>          private void CriaDiretorios()
>          {
>              DirReceb = "RECEBIDOS\\" +
> DateTime.Now.Year.ToString() + "\\";
>              // Cria o diretorio "root"
>              if (!Directory.Exists(DirReceb))
>                  Directory.CreateDirectory(DirReceb);
>
>              // cria os diretorios dos meses do ano
>              for (int i = 0; i < 12; i++)
>                  if (!Directory.Exists(DirReceb + MesesDoAno))
>                      Directory.CreateDirectory(DirReceb +
> MesesDoAno[i]);
>
>              // cria os diretorios com os dias dos meses e ano
>              for (int i = 1; i <= 12; i++)
>              {
>                  string dia;
>                  string mes;
>                  var ano = DateTime.Now.Year;
>                  var DiasDoMes =
> DateTime.DaysInMonth(DateTime.Now.Year, i);
>
>                  if (i < 10)
>                      mes = "0" + i.ToString();
>                  else
>                      mes = i.ToString();
>
>                  for (int j = 1; j <= DiasDoMes; j++)
>                  {
>                      if (j < 10)
>                          dia = "0" + j.ToString();
>                      else
>                          dia = j.ToString();
>
>                      string StrDia = 
> string.Format("{0}-{1}-{2}",
> dia, mes, ano);
>                      string StrData = DirReceb + 
> MesesDoAno[i-1] +
> "\\" + StrDia;
>
>                      if (!Directory.Exists(StrData))
>                          Directory.CreateDirectory(StrData);
>                  }
>              }
>          }
>
>          private void MoveArquivos()
>          {
>              string[] filters = new[] { "*.REM", "*.RET" };
>
>              for (int i = 0; i < 2; i++)
>              {
>                  DirectoryInfo di = new
> DirectoryInfo(Directory.GetCurrentDirectory());
>                  var files = di.GetFiles(filters[i]);
>
>                  foreach (var fi in files)
>                  {
>                      var mes = fi.CreationTime.Month;
>                      var strdt =
> fi.CreationTime.ToString("dd-MM-yyyy");
>
>                      string DestDir = DirReceb + MesesDoAno[mes 
> -
> 1] + "\\" + strdt + "\\" + fi.Name;
>
>                      File.Move(fi.Name, DestDir);
>                  }
>              }
>          }
>      }
>
>      class Program
>      {
>          static void Main(string[] args)
>          {
>              try
>              {
>                  new Organiza();
>              }
>              catch (Exception ex)
>              {
>                  Console.WriteLine(ex.Message);
>              }
>          }
>      }
> }
>
>
> So, to create directory and move files... I get the 
> documentation
> on that page: http://dlang.org/phobos/std_file.html
>
> But, I don't know, How I can get the file information and what 
> is
> the best way to create the directory's, so, I need some help :)
>
> I appreciate the help :)

Hi Alexandre,

Would you mind explaining in English what it is that you would 
like to achieve. I cannot read [what I assume is] Portuguese, but 
if you can explain what you wan't I will try my best to help.


More information about the Digitalmars-d-learn mailing list