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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
// 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;
//bool DirectoryRecursive(char * path = new char[261])
bool DirectoryRecursive(char path[261])
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
DWORD Attributes;
strcat(path,"\\*");
//path[strlen(path)] = '*';
hFind = FindFirstFile(path, &FindFileData);
printf("---Recursive: %s\n",path);
do{
if (!(FindFileData.cFileName == ".") || (FindFileData.cFileName == "..")){
//Str append Example
char str[MAX_PATH];
strcpy (str,path);
str[strlen(path)-1] = '\0';
strcat (str,FindFileData.cFileName);
_tprintf (TEXT("---File Found: %s\n"),str);
Attributes = GetFileAttributes(str);
_tprintf (TEXT("---File Attributes: %d\n"),Attributes);
if (Attributes & FILE_ATTRIBUTE_DIRECTORY)
{
//is directory
printf("---Directory\n");
DirectoryRecursive(str);
}
else
{
//not directory
printf("---File\n");
}
}
}while(FindNextFile(hFind, &FindFileData));
return true;
}
int main()
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
//Read list file
FILE *filein;
long lSize;
char * buffer;
size_t result;
DWORD Attributes;
//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 apc
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{
if ((FindFileData.cFileName != ".") || (FindFileData.cFileName != "..")){
//Str append Example
char str[MAX_PATH];
strcpy (str,token);
str[strlen(token)-1] = '\0';
strcat (str,FindFileData.cFileName);
_tprintf (TEXT("File Found: %s\n"),str);
Attributes = GetFileAttributes(str);
_tprintf (TEXT("File Attributes: %d\n"),Attributes);
if (Attributes & FILE_ATTRIBUTE_DIRECTORY)
{
//is directory
printf("Directory\n");
//DirectoryRecursive(str);
}
else
{
//not directory
printf("File\n");
}
}
}while(FindNextFile(hFind, &FindFileData));
FindClose(hFind);
// Get next token:
token = strtok( NULL,"\r\n"); // C4996
}
free(buffer);
return 0;
}
|