需要了解_findfirst和_findnext如何使用模式输入。
我曾经按照代码来分析他们的功能,但结果让我感到困惑。
intptr_t handle;
struct _finddata_t fblock;
int count = 1;
char pattern[] = "*";
printf("Pattern is %s",pattern);
if((handle = _findfirst(pattern,&fblock))>0){
printf("\nfound : %d :: ",count++);
printf("%s",fblock.name);
while(_findnext(handle,&fblock) == 0){
printf("\nfound : %d :: ",count++);
printf("%s",fblock.name);
}
}
printf("\ncompleted");
//getch();
结果: 我在文件夹中有四个文件。
1.ReadMe.txt
2.ReadMe1.txt
3.ReadMe1.txt_bck
4.ReadMe1.txtbck
现在,
Enter pattern :*.tx
Pattern is *.tx
completed
确定。没有带有ext tx的文件
Enter pattern :*.txt_
Pattern is *.txt_
completed
确定。没有带有ext txt_的文件
Enter pattern :*.txt
Pattern is *.txt
found : 1 :: ReadMe.txt
found : 2 :: ReadMe1.txt
found : 3 :: ReadMe1.txtbck
found : 4 :: ReadMe1.txt_bck
completed
???我只询问了ext txt。为什么要显示txt_bck?
Enter pattern :*.txt*
Pattern is *.txt*
found : 1 :: ReadMe.txt
found : 2 :: ReadMe1.txt
found : 3 :: ReadMe1.txtbck
found : 4 :: ReadMe1.txt_bck
completed
现在这与prev之间的差异是什么?
Enter pattern :ReadMe?.txt
Pattern is ReadMe?.txt
found : 1 :: ReadMe.txt
found : 2 :: ReadMe1.txt
completed
期待“?”通配符只匹配一个字符但它也匹配0。
Enter pattern :ReadMe*.txt
Pattern is ReadMe*.txt
found : 1 :: ReadMe.txt
found : 2 :: ReadMe1.txt
found : 3 :: ReadMe1.txtbck
found : 4 :: ReadMe1.txt_bck
completed
_