我有一个函数,加载给定的文件夹中的所有* .txt和所有它的子文件夹。我想获得实际的进展(例如15/35加载)。如何在递归爬取目录结构时取得进展?
但我想不出如何获得加载到目录下一级目录结构的文件数目,以添加到当前索引。
* a
* b
- 1.txt (file in dir b)
- 1.txt (file in dir a)
- 2.txt _(index of this file is 3 - one file from dir below, one file in this dir)_
代码:
public int getFilesInSubfolders(directory)
{
int count = 0;
foreach (subdirectory in directory)
{
count += getFilesInSubfolders();
}
foreach (txtfile in folderFiles)
{
load(txtfile);
count++;
updateProgress(actualIndex); // how to get the actual index? e.g. 15/35 loaded, so that 15
}
return count;
}
这是一个鸡与鸡蛋的问题。记录你上次找到多少个文件,这是下一次的事。 – 2013-05-11 18:10:02