Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <tchar.h>
- #include <stdio.h>
- #include <string.h>
- WIN32_FIND_DATA FindFileData;
- HANDLE hFind;
- void files(HANDLE hFind,TCHAR r[]);
- void onlyfiles(HANDLE hFind,TCHAR r[]);
- TCHAR pd[]="C:\\d\\";
- TCHAR z[]="*.*";
- TCHAR r[];
- TCHAR data[];
- struct node{
- struct node *link;
- char folder[];
- };
- struct node *start = NULL;//initialiser au null
- struct node *newnode;
- void insertatend(struct node *start,char *data){
- struct node *p,*temp;
- temp=(struct node *)malloc(sizeof(struct node));
- strcpy(temp->folder,data);
- p=start;
- while(p->link!=NULL)
- p=p->link;
- p->link=temp;
- temp->link=NULL;
- }
- void displaylist(struct node *start){
- struct node *p;
- if(start==NULL)
- {
- printf("list is empty\n");
- return;
- }
- p=start->link;
- while(p!=NULL)
- {
- _tprintf (TEXT("Target file is %s\n"), p->folder);
- //strcpy(r,p->folder);
- //strcat(r, "\\*.*");
- //onlyfiles(hFind,r);
- p=p->link;
- }
- printf("\n");
- }//end of displaylist()
- void _tmain()
- {
- strcpy(data,pd);
- newnode=malloc(sizeof(struct node));
- strcpy(newnode->folder,pd);
- newnode->link=NULL;
- start=newnode;
- strcat(r, pd);
- strcat(r, z);
- files(hFind,r);
- FindClose(hFind);
- displaylist(start);
- }
- void files(HANDLE hFind,TCHAR r[]){
- hFind = FindFirstFile(r, &FindFileData);
- if (hFind == INVALID_HANDLE_VALUE)
- {
- printf ("FindFirstFile failed (%d)\n", GetLastError());
- return;
- }
- if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && strcmp(FindFileData.cFileName, ".") != 0 && strcmp(FindFileData.cFileName, "..") != 0){
- _tprintf (TEXT("The first file found is %s\n"),
- FindFileData.cFileName);
- }
- while(FindNextFile(hFind, &FindFileData) != 0){
- if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && strcmp(FindFileData.cFileName, ".") != 0 && strcmp(FindFileData.cFileName, "..") != 0){
- strcat(data, FindFileData.cFileName);
- strcat(data, "\\");
- insertatend(start,data);
- strcpy(data,pd);
- }
- }
- }
- void onlyfiles(HANDLE hFind,TCHAR r[]){
- _tprintf (TEXT("The first file found is %s\n"),
- r);
- hFind = FindFirstFile(r, &FindFileData);
- if (hFind == INVALID_HANDLE_VALUE)
- {
- printf ("FindFirstFile failed (%d)\n", GetLastError());
- return;
- }
- if(strcmp(FindFileData.cFileName, ".") != 0 &&
- strcmp(FindFileData.cFileName, "..") != 0){
- _tprintf (TEXT("The first file found is %s\n"),
- FindFileData.cFileName);
- }
- while(FindNextFile(hFind, &FindFileData) != 0){
- if(!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp(FindFileData.cFileName, ".") != 0 && strcmp(FindFileData.cFileName, "..") != 0){
- _tprintf (TEXT("The first file found is %s\n"),
- FindFileData.cFileName);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement