<pre name="code" class="csharp">
string Filepath = ConfigurationSettings.AppSettings["FilePath"]; //要导入文件路径
string pathbackup = ConfigurationSettings.AppSettings["FileBack"]; //备份目录
string fileName = string.Empty; //文件名
List<string> lis = new List<string>();
List<string> lis_YJZT = new List<string>();
List<string> lis_Filename = new List<string>();
try
{
if (!Directory.Exists(Filepath))//是否存在目录
{ Directory.CreateDirectory(Filepath); }
if (!Directory.Exists(pathbackup))//是否存在备份目录
{ Directory.CreateDirectory(pathbackup); }
//检查文件是否存在
NFileDirectoryEnumerator file = new NFileDirectoryEnumerator();
file.SearchPath = Filepath;
file.Reset();
file.ReturnStringType = true;
setLog("路径文件检测完成。。。"); //系统显示
Thread.Sleep(50);
lis.Clear();
//获取文件名
DirectoryInfo dir = new DirectoryInfo(Filepath);
foreach (DirectoryInfo item in dir.GetDirectories())
{
lis_Filename.Add(item.Name); //获取文件夹下面所有的文件名,并保存
}
while (file.MoveNext())
{
if (file.IsFile) //单一文件夹
{
<span style="white-space:pre"> </span> <span style="font-family: Arial, Helvetica, sans-serif;"> </span><span style="font-family: Arial, Helvetica, sans-serif;">//获取文件夹下面.bcp文件文件名,并保存</span><span style="white-space:pre">
</span> fileName = file.Name;
if (fileName.Substring(fileName.Length - 3, 3).ToLower() == "bcp")
{
lis.Add(fileName);
lis_YJZT.Add("0");
}
}
else //文件夹下含有子文件夹
{
if (lis_Filename.Count > 0)
{
for (int i = 0; i < lis_Filename.Count; i++)
{
NFileDirectoryEnumerator eC = new NFileDirectoryEnumerator();
eC.SearchPath = Filepath + "\\" + lis_Filename[i].ToString();
eC.Reset();
eC.ReturnStringType = true;
while (eC.MoveNext())
{
if (eC.IsFile)
{
fileName = eC.Name;
if (fileName.Substring(fileName.Length - 3, 3).ToLower() == "bcp")
{
lis.Add(lis_Filename[i] + "\\" + fileName);
lis_YJZT.Add("1");
}
}
}
eC.Close();
}
break;
}
}
}
file.Close(); //释放
}
catch (Exception ex)
{
Logger.Write("数据扫描" + ex.Message);
}
//<span style="font-family: Arial, Helvetica, sans-serif;">NFileDirectoryEnumerator 类详见其他博客</span>