如何读取仅在今天创建的子文件夹中的CSV文件

时间:2018-03-06 06:24:13

标签: c# c#-4.0 c#-3.0

1.我有一个根位置(\ Wna \ sv_prod_01 \ USERS \ Results \ thorn-prod)这个位置有500个文件夹,其中只有今天创建的20个文件夹,每个文件夹名称都以单词PREBATCH开头。

2.我担心的是如何计算从名称PREBATCH

开始的20个文件夹中的csv

这是我试过的:

            DateTime today = DateTime.Now.Date;
            var directoryInfo = new System.IO.DirectoryInfo(@"\\\\\Wna001\sv_prod_01\USERS\Results\thorn-prod\");
            int directoryCount = directoryInfo.GetDirectories().Where(x => x.CreationTime.Date == today || x.LastWriteTime == today).Count();====this code is used to count the file which generated today only 

            string[] dirs = Directory.GetDirectories(@"\\\\\Wna001\sv_prod_01\USERS\Results\thorn-prod\", "*PREBATCH*"); ====this code is used to read the folder which start with word PREBATCH

            foreach (string dir in dirs)
            {
                int directoryCount1 = Directory.GetFiles("*.csv");
            }

1 个答案:

答案 0 :(得分:0)

您可以使用<?php $status = 'On time'; if ($status === 'On time'){ $color = "green"; } elseif ($status === 'No data') { $status = "Address Not Found"; $color = "red"; } else { $status = "Free Slot"; $color = "grey"; } ?> <table> <tr> <td style="background-color: <?php echo $color; ?>"><?php echo $status; ?></td> </tr> </table> 选项查看文件夹的所有目录,

更改此类代码,

SearchOption.AllDirectories

注意:您的根目录是 int count = 0; string[] dirs = Directory.GetDirectories(@"\\\\\Wna001\sv_prod_01\USERS\Results\thorn-prod\", "*PREBATCH*", SearchOption.AllDirectories); foreach (string dir in dirs) { var csvFiles = Directory.GetFiles(dir,"*.csv"); foreach (var file in csvFiles) { if(File.GetCreationTime(file) > DateTime.Now.Date) { count ++; } } }