以下代码仅返回循环中的最新值。我需要做些什么才能显示正在迭代的所有值?我使用此方法而不是@Mapper
public interface MyMapper {
default PersonDTO personBLOToPersonDTO(PersonBLO personBLO) {
if (personBLO == null) {
return null;
}
PersonDTO dto = personToPersonDTO(personBlo.getPerson());
// the rest of the mapping
return dto;
}
PersonDTO personToPersonDTO(PersonBLO source);
}
的原因是因为有一个我无法访问的文件夹路径。我确实尝试将SearchOption.AllDirectory
与UnauthorizedAccessException
和try
一起使用,但是返回一个空值,因为它一直在终止循环。
catch
答案 0 :(得分:0)
尝试删除函数外的FileList
声明,同时删除循环外的Dts.Variables["User::objDirectoryList"].Value = FileList;
:
System.Collections.ArrayList FileList = new System.Collections.ArrayList();
public void Main()
{
string path = @"drive"; // TODO
ApplyAllFiles(path, ProcessFile);
Dts.Variables["User::objDirectoryList"].Value = FileList;
}
public void ProcessFile(string path)
{
/* ... */
}
public void ApplyAllFiles(string folder, Action<string> fileAction)
{
List<string> logger = new List<string>();
DateTime DateFilter = DateTime.Now.AddMonths(-6);
foreach (string file in Directory.GetDirectories(folder))
{
fileAction(file);
}
foreach (string subDir in Directory.GetDirectories(folder))
{
string rootfolder = "root folder";
if (subDir.Contains(rootfolder))
{
FileList.Add(subDir);
//MessageBox.Show(subDir);
}
try
{
ApplyAllFiles(subDir, fileAction);
}
catch (UnauthorizedAccessException e)
{
logger.Add(e.Message);
}
catch (System.IO.DirectoryNotFoundException e)
{
logger.Add(e.Message);
}
}
}