1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
// del2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include "Shlwapi.h"
using namespace std;
int main()
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
//Read list file
FILE *filein;
long lSize;
char * buffer;
size_t result;
//Get path to list.txt
char szFileName[MAX_PATH];
HINSTANCE hInstance = GetModuleHandle(NULL);
GetModuleFileName(hInstance, szFileName, MAX_PATH);
PathRemoveFileSpec(szFileName);
PathAppend(szFileName,"\\list.txt");
//Open file
filein = fopen(szFileName, "r");
//if (filein==NULL) {fputs ("File error",stderr); exit (1);}
// obtain file size:
fseek (filein , 0 , SEEK_END);
lSize = ftell (filein);
rewind (filein);
// allocate memory to contain the whole file:
buffer = (char*) malloc ((sizeof(char)*lSize)+1);
// copy the file into the buffer:
result = fread (buffer,1,lSize,filein);
buffer[result] = '\0'; // make extra byte nul
/*//Print some info
printf ("%s\n",buffer);// list.txt
printf ("%s\n",szFileName);//Path
fclose(filein);
*/
//token
char *token;
token = strtok(buffer,"\r\n");
while( token != NULL )
{
// While there are tokens in "string"
printf( "%s\n", token );
//char *temp;
//strncpy (temp,token,strlen(token)-1);
//printf("%d\n",strlen(token)-1);
/*Str append Example
char str[strlen(token) + strlen(FindFileData.cFileName)];
strcpy (str,"these ");
strcat (str,"strings ");
strcat (str,"are ");
strcat (str,"concatenated.");
printf("%s\n",str);
*/
//List files
hFind = FindFirstFile(token, &FindFileData);
do{
_tprintf (TEXT("File Found: %s%s\n"),FindFileData.cFileName,token);
}while(FindNextFile(hFind, &FindFileData));
FindClose(hFind);
// Get next token:
token = strtok( NULL,"\r\n"); // C4996
}
free(buffer);
return 0;
}
|