目录和子目录路径不起作用

时间:2018-07-18 05:19:17

标签: c# directory console-application subdirectory document-root

我有以下代码,我遇到的问题是它只查看根目录,而不是根目录内的子文件夹,我该如何更改它,以便它也能查看子目录

DirectoryInfo di = new DirectoryInfo(@"C:\Users\allens\Desktop\test");             
DateTime newdate = DateTime.Now.AddHours(-24);                                     

FileInfo[] SWADimg = di.GetFiles("*.jpg");                                        
if (SWADimg.Length == 0)                                                       
{
    var smtpClient = new SmtpClient
    {
        Host = "your.company.smtp.server",                                    
        UseDefaultCredentials = false,
        EnableSsl = true,
        Credentials = new NetworkCredential("account_to_use", "password")
    };

    var message = new MailMessage                                              
    {
        Subject = "SWAD Error",
        Body = "Swad has failed to sync images",
        IsBodyHtml = true,
        From = new MailAddress("//from email address needed")
    };

    message.To.Add(new MailAddress("ALL@jnb.com"));


    smtpClient.Send(message);
} else 
{
    Console.WriteLine("no files present");
    Console.ReadLine();
}

1 个答案:

答案 0 :(得分:0)

这是用于递归列出目录中所有文件的代码。

Array
(
    [0] => tripID
    [1] => cabID
)

您只需要添加一些内容即可保存或打印信息。