给出 临时工作文件名和路径,要查的文件夹路径和文件夹名。
用 DOS 命令获文件名
#include
#include
#define Buff_size 4096
FILE *fin;
void main (int argc, char *argv[])
{
char current_dir[72], namelist[72],current_file_name[72];
char command[200];
int i,j,n=0;
char *buff;
buff = (char *) malloc( Buff_size * sizeof (char));
if (!buff) {
printf("\007No enough memory -- Can not alloc the Buff\n");
exit(2);
};
strcpy(namelist,"C:\\temp\\abc.lis"); // 临时工作文件名和路径
strcpy(current_dir, "D:\\zzz"); //要查的文件夹路径和文件夹名
sprintf(command,"DIR/B/A-D %s > %s", current_dir, namelist);
system(command);
if ( (fin = fopen(namelist,"r") ) == NULL ) {
printf("\007Cann't open work file: %s ", namelist);exit(1);
};
while ( fgets( current_file_name, 72, fin) !=NULL ) n=n+1;
rewind(fin);
printf("\007total %d files\n",n);
for (i=0;i
printf("%s",current_file_name);
}
exit(0);
}
#include
.....
string str;
char ch[50];
....
cin>>str;
for (long a=0;a
ch[a]=str[a];
}
freopen(ch,"r",stdin);
.....
这样加进去就可以了
另外,虚机团上产品团购,超级便宜