digitalmars.D - Help to convert a code to D
- Alexandre (108/108) Aug 26 2013 Hi :)
 - Olivier Pisano (12/12) Aug 26 2013 Hi Alexandre, welcome aboard !
 - Alexandre (3/26) Aug 26 2013 Sorry for my mistake :(
 - Joseph Rushton Wakeling (6/7) Aug 26 2013 There will be lots of people willing to offer it, but you'll probably ge...
 
Hi :)
to D...
with all days of month of specific year...
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 :)
 Aug 26 2013
Hi Alexandre, welcome aboard ! This kind of question should ideally be asked in the d.learn forum, not here. Anyway, to create directories, you can use std.file mkdir and mkdirRecurse function. To get file information, there is the getAttributes function in the same module. Note that for builing path names, you can use std.path buildPath function, which is portable between Windows and UNIX : string DestDir = buildPath(DirReceb ~ MesesDoAno[mes - 1], strdt, fi.Name); Cheers, Olivier
 Aug 26 2013
On Monday, 26 August 2013 at 13:19:59 UTC, Olivier Pisano wrote:Hi Alexandre, welcome aboard ! This kind of question should ideally be asked in the d.learn forum, not here. Anyway, to create directories, you can use std.file mkdir and mkdirRecurse function. To get file information, there is the getAttributes function in the same module. Note that for builing path names, you can use std.path buildPath function, which is portable between Windows and UNIX : string DestDir = buildPath(DirReceb ~ MesesDoAno[mes - 1], strdt, fi.Name); Cheers, OlivierSorry for my mistake :( So, I will make that post on the correct forum :)On Monday, 26 August 2013 at 13:21:30 UTC, Joseph Rushton Wakeling wrote: On 26/08/13 15:07, Alexandre wrote:I appreciate the help :)There will be lots of people willing to offer it, but you'll probably get more (and better) feedback if you take these kinds of questions to the D.learn forum/mailing list. :-) http://forum.dlang.org/group/digitalmars.D.learn http://lists.puremagic.com/cgi-bin/mailman/listinfo/digitalmars-d-learn
 Aug 26 2013
On 26/08/13 15:07, Alexandre wrote:I appreciate the help :)There will be lots of people willing to offer it, but you'll probably get more (and better) feedback if you take these kinds of questions to the D.learn forum/mailing list. :-) http://forum.dlang.org/group/digitalmars.D.learn http://lists.puremagic.com/cgi-bin/mailman/listinfo/digitalmars-d-learn
 Aug 26 2013








 
 
 
 "Alexandre" <alebencz gmail.com> 