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 132 133 134 135 136 137 138 139 140 141 142
|
#include <stdio.h>
#include <windows.h>
#include <string.h>
#include <stdlib.h>
class queue{
private:
struct item{
char src[255] ;
struct item *next ;
} ;
typedef struct item ITEM ;
ITEM* head_ptr ;
ITEM* tail_ptr ;
public:
queue() ;
~queue() ;
int empty() ;
void front(char *src) ;
void pop() ;
void push(char *src) ;
} ;
queue::queue()
{
head_ptr = NULL ;
tail_ptr = NULL ;
}
void queue::push(char *src)
{
ITEM* temp = (ITEM*)malloc(sizeof(temp)) ;
strcpy(temp->src, src) ;
temp->next = NULL ;
if (head_ptr == NULL){
head_ptr = temp ;
//tail_ptr = temp ;
}else{
tail_ptr->next = temp ;
}
tail_ptr = temp ;
}
void queue::pop()
{
ITEM* temp = NULL ;
temp = head_ptr ;
head_ptr = head_ptr->next ;
if (head_ptr == NULL){
tail_ptr = NULL ;
}else{
head_ptr = head_ptr->next ;
}
free(temp) ;
}
int queue::empty()
{
return (head_ptr == NULL) ;
}
void queue::front(char *src)
{
if (head_ptr) strcpy(src, head_ptr->src) ;
}
queue::~queue()
{
ITEM* temp = NULL ;
while (head_ptr->next){
temp = head_ptr ;
head_ptr = head_ptr->next ;
free(temp) ;
}
free(head_ptr) ;
head_ptr = NULL ;
tail_ptr = NULL ;
}
struct OPERATIONDESC{
char src[255] ;
char dest[255] ;
} ;
void folder_traverse(void *id)
{
char level[255] ;
char temp[255] ;
char temp_1[255] ;
HANDLE h ;
WIN32_FIND_DATA info ;
struct OPERATIONDESC* op = (struct OPERATIONDESC*)id ;
queue q ;
q.push(op->src) ;
while (!q.empty()){
q.front(level) ;
q.pop() ;
strcpy(temp, level) ;
strcat(temp, "\\*.*") ;
h = FindFirstFile(temp, &info) ;
do{
if (!strcmp(info.cFileName, ".")) continue ;
if (!strcmp(info.cFileName, "..")) continue ;
strcpy(temp_1, level) ;
strcat(temp_1, "\\") ;
strcat(temp_1, info.cFileName) ;
if(info.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY){
q.push(temp_1) ;
}else{
printf("%s\n", temp_1) ;
}
}while (FindNextFile(h, &info)) ;
}
}
int main()
{
struct OPERATIONDESC d ;
strcpy(d.src, "c:\\test") ;
folder_traverse((void*)&d) ;
return 0 ;
}
|