Advertisement
Guest User

Untitled

a guest
Oct 14th, 2016
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1.  
  2. #include <windows.h>
  3. #include <tchar.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7. WIN32_FIND_DATA FindFileData;
  8. HANDLE hFind;
  9. void files(HANDLE hFind,TCHAR r[]);
  10. void onlyfiles(HANDLE hFind,TCHAR r[]);
  11.  
  12. TCHAR pd[]="C:\\d\\";
  13. TCHAR z[]="*.*";
  14. TCHAR r[];
  15. TCHAR data[];
  16.  
  17. struct node{
  18.  
  19.  
  20. struct node *link;
  21. char folder[];
  22. };
  23. struct node *start = NULL;//initialiser au null
  24. struct node *newnode;
  25. void insertatend(struct node *start,char *data){
  26. struct node *p,*temp;
  27. temp=(struct node *)malloc(sizeof(struct node));
  28.  
  29.  
  30. strcpy(temp->folder,data);
  31. p=start;
  32. while(p->link!=NULL)
  33. p=p->link;
  34. p->link=temp;
  35. temp->link=NULL;
  36. }
  37.  
  38. void displaylist(struct node *start){
  39.  
  40. struct node *p;
  41. if(start==NULL)
  42. {
  43. printf("list is empty\n");
  44. return;
  45. }
  46.  
  47. p=start->link;
  48.  
  49. while(p!=NULL)
  50. {
  51.  
  52. _tprintf (TEXT("Target file is %s\n"), p->folder);
  53. //strcpy(r,p->folder);
  54. //strcat(r, "\\*.*");
  55. //onlyfiles(hFind,r);
  56.  
  57.  
  58. p=p->link;
  59.  
  60.  
  61. }
  62.  
  63.  
  64. printf("\n");
  65. }//end of displaylist()
  66.  
  67. void _tmain()
  68.  
  69. {
  70. strcpy(data,pd);
  71.  
  72.  
  73. newnode=malloc(sizeof(struct node));
  74.  
  75. strcpy(newnode->folder,pd);
  76. newnode->link=NULL;
  77. start=newnode;
  78.  
  79. strcat(r, pd);
  80. strcat(r, z);
  81.  
  82. files(hFind,r);
  83. FindClose(hFind);
  84. displaylist(start);
  85.  
  86. }
  87. void files(HANDLE hFind,TCHAR r[]){
  88.  
  89.  
  90.  
  91. hFind = FindFirstFile(r, &FindFileData);
  92. if (hFind == INVALID_HANDLE_VALUE)
  93. {
  94. printf ("FindFirstFile failed (%d)\n", GetLastError());
  95. return;
  96. }
  97. if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && strcmp(FindFileData.cFileName, ".") != 0 && strcmp(FindFileData.cFileName, "..") != 0){
  98. _tprintf (TEXT("The first file found is %s\n"),
  99. FindFileData.cFileName);
  100. }
  101.  
  102. while(FindNextFile(hFind, &FindFileData) != 0){
  103. if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && strcmp(FindFileData.cFileName, ".") != 0 && strcmp(FindFileData.cFileName, "..") != 0){
  104.  
  105. strcat(data, FindFileData.cFileName);
  106. strcat(data, "\\");
  107.  
  108. insertatend(start,data);
  109. strcpy(data,pd);
  110.  
  111.  
  112.  
  113. }
  114.  
  115.  
  116.  
  117.  
  118. }
  119. }
  120. void onlyfiles(HANDLE hFind,TCHAR r[]){
  121. _tprintf (TEXT("The first file found is %s\n"),
  122. r);
  123.  
  124. hFind = FindFirstFile(r, &FindFileData);
  125. if (hFind == INVALID_HANDLE_VALUE)
  126. {
  127. printf ("FindFirstFile failed (%d)\n", GetLastError());
  128. return;
  129. }
  130. if(strcmp(FindFileData.cFileName, ".") != 0 &&
  131. strcmp(FindFileData.cFileName, "..") != 0){
  132. _tprintf (TEXT("The first file found is %s\n"),
  133. FindFileData.cFileName);
  134. }
  135.  
  136. while(FindNextFile(hFind, &FindFileData) != 0){
  137. if(!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp(FindFileData.cFileName, ".") != 0 && strcmp(FindFileData.cFileName, "..") != 0){
  138.  
  139. _tprintf (TEXT("The first file found is %s\n"),
  140. FindFileData.cFileName);
  141.  
  142.  
  143. }
  144.  
  145.  
  146.  
  147.  
  148. }
  149.  
  150.  
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement