summaryrefslogtreecommitdiffstats
path: root/converter/source/printdir.c
diff options
context:
space:
mode:
authoradmin@omencraft.com <admin@omencraft.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-11-05 01:23:32 +0100
committeradmin@omencraft.com <admin@omencraft.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-11-05 01:23:32 +0100
commitdd36ea269fb3364e0b1c7d324e8e9a42ddad610f (patch)
tree9c3f647e5081a9b0dccc0f51277f480711aad8ab /converter/source/printdir.c
parentlast file... finally (diff)
downloadcuberite-dd36ea269fb3364e0b1c7d324e8e9a42ddad610f.tar
cuberite-dd36ea269fb3364e0b1c7d324e8e9a42ddad610f.tar.gz
cuberite-dd36ea269fb3364e0b1c7d324e8e9a42ddad610f.tar.bz2
cuberite-dd36ea269fb3364e0b1c7d324e8e9a42ddad610f.tar.lz
cuberite-dd36ea269fb3364e0b1c7d324e8e9a42ddad610f.tar.xz
cuberite-dd36ea269fb3364e0b1c7d324e8e9a42ddad610f.tar.zst
cuberite-dd36ea269fb3364e0b1c7d324e8e9a42ddad610f.zip
Diffstat (limited to '')
-rw-r--r--converter/source/printdir.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/converter/source/printdir.c b/converter/source/printdir.c
new file mode 100644
index 000000000..ad0492f98
--- /dev/null
+++ b/converter/source/printdir.c
@@ -0,0 +1,52 @@
+/* list contents of a directory */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include "dirent.h"
+
+int main (int argc, char *argv[]) {
+ int i;
+
+ /* check command line arguments */
+ if (argc <= 1) {
+ fprintf (stderr, "usage: printdir directory\n");
+ return EXIT_FAILURE;
+ }
+
+ /* print contents of directories listed in command line */
+ i = 1;
+ while (i < argc) {
+ DIR *dir;
+ struct dirent *ent;
+
+ /* open directory stream */
+ dir = opendir (argv[i]);
+ if (dir != NULL) {
+
+ /* print all the files and directories within directory */
+ while ((ent = readdir (dir)) != NULL) {
+ switch (ent->d_type) {
+ case DT_REG:
+ printf ("%*.*s\n", ent->d_namlen, ent->d_namlen, ent->d_name);
+ break;
+
+ case DT_DIR:
+ printf ("%s (dir)\n", ent->d_name);
+ break;
+
+ default:
+ printf ("%s:\n", ent->d_name);
+ }
+ }
+
+ closedir (dir);
+ } else {
+ /* could not open directory */
+ perror ("");
+ return EXIT_FAILURE;
+ }
+ i++;
+ }
+ return EXIT_SUCCESS;
+}