Browse Source

Merge branch 'myls' of https://github.com/Loquicom/SEC into myls

MaxenceBacquet 6 years ago
parent
commit
35430eb1c9
1 changed files with 43 additions and 0 deletions
  1. 43 0
      myls.c

+ 43 - 0
myls.c

@@ -0,0 +1,43 @@
+#define _DEFAULT_SOURCE
+
+#include <dirent.h>
+#include "parser.h"
+
+
+void lsBasics(int argc, char* argv[]){
+    char buffer[BUFFER_SIZE];
+    struct dirent** contentsDir;
+    int i = 0, nbFile;
+
+    //Recuperation chemin actuel
+    if (getcwd(buffer, sizeof (buffer)) == NULL) {
+        addperror("Erreur getcwd()");
+        return;
+    }
+
+    //Ouverture et lecture DIR
+    if((path = opendir(buffer)) == NULL){
+        addperror("Erreur opendir()")
+        return;
+    }
+
+    //Recup la liste des fichiers dans le dossier courant
+    nbFile = scandir(buffer, &contentsDir, 0, alphasort);
+    if (nbFile < 0) {
+        addperror("Erreur scandir()");
+        return;
+    }
+
+    //Affiche les fichiers
+    while(i < nbFile){
+        printf("%s\n", contentsDir[i]->d_name);
+        i++;
+    }
+
+    return;
+}
+
+
+int main(int argc, char* argv[]){
+    lsBasics(argc, argv);
+}