Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _GNU_SOURCE
- #include <dirent.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <errno.h>
- #include <utime.h>
- typedef struct myNode {
- char *name;
- } myNode;
- typedef struct myList {
- myNode *node;
- struct myList *next;
- } myList;
- void addToList(myList* root, myNode* node) {
- if (root->node == NULL) {
- root->node = node;
- root->next = NULL;
- }
- else {
- while (root->next != NULL) {
- root = root->next;
- }
- root->next = malloc(sizeof(myList));
- root->next->node = node;
- root->next->next = NULL;
- }
- }
- myList* createList() {
- myList* list = malloc(sizeof(myList));
- list->node = NULL;
- list->next = NULL;
- return list;
- }
- myNode* createNode(char* name) {
- myNode* node = malloc(sizeof(myNode));
- node->name = name;
- return node;
- }
- void myPrint(myList* root) {
- if (root == NULL) return;
- printf("address: %p, name: %s\n", (void*) root->node, root->node->name);
- myPrint(root->next);
- }
- myList* listFilesInDirectory(char* path) {
- DIR* dir = opendir(path);
- myList* list = createList();
- struct dirent* entry;
- while ((entry = readdir(dir)) != NULL) {
- myNode* node = createNode(entry->d_name);
- addToList(list, node);
- }
- closedir(dir);
- return list;
- }
- int main() {
- myList* sourceFiles = listFilesInDirectory("source/");
- printf("SourceFiles content 1:\n");
- myPrint(sourceFiles);
- printf("-----------\n");
- myList* destFiles = listFilesInDirectory("dest/");
- printf("SourceFiles content 2:\n");
- myPrint(sourceFiles);
- printf("-----------\n");
- printf("DestFiles content:\n");
- myPrint(destFiles);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement