Ok Here's my code. It compiles fine, but it don't list me files indirectory.
In list.txt I have "C:\users\rain" but my program shows following output.
Code:
C:\Users\rain>D:\Development\Cplusplus\del\del2\Debug\del2.exe
C:\users\rain
File Found: rain
C:\Users\rain>
I tried changing "C:\users\rain" to "C:\users\rain\" but then output is like this:
Code:
The first file found is ╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠
╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠
╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠
╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠
ńŅ▀D..,
I can't find out why it shows only File Found: rain. I have many files and folders in "C:\users\rain" and none of them are called "rain"
Code:
#include "stdafx.h"
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include "Shlwapi.h"
using namespace std;
void 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 );
//List files
hFind = FindFirstFile(token, &FindFileData);
do{
_tprintf (TEXT("File Found: %s\n"),FindFileData.cFileName);
}while(FindNextFile(hFind, &FindFileData));
FindClose(hFind);
// Get next token:
token = strtok( NULL,"\r\n"); // C4996
}
}