Exemplo n.º 1
0
int main(int argc, char** argv) {

	// decide which directory to read
	char* directory;
	if (argc > 1) {
		char* argument = argv[1];
		if (strlen(argument) < G_PATH_MAX) {
			directory = argument;
		} else {
			fprintf(stderr, "given argument is not a valid path name\n");
			return 1;
		}
	} else {
		directory = new char[G_PATH_MAX];
		g_get_working_directory(directory);
	}

	// open the directory
	g_fs_open_directory_status stat;
	auto* iter = g_open_directory_s(directory, &stat);

	// check for errors
	if (stat != G_FS_OPEN_DIRECTORY_SUCCESSFUL) {
		fprintf(stderr, "failed to read directory\n");
		return 1;
	}

	g_fs_directory_entry* entry;
	while (true) {
		g_fs_read_directory_status rstat;
		entry = g_read_directory_s(iter, &rstat);

		if (rstat == G_FS_READ_DIRECTORY_SUCCESSFUL) {
			if (entry == 0) {
				break;
			}

			if (entry->type == G_FS_NODE_TYPE_FILE) {
				printf("   ");
			} else if (entry->type == G_FS_NODE_TYPE_FOLDER) {
				printf(" + ");
			} else {
				printf(" ~ ");
			}
			printf("%s\n", entry->name);

		} else if (rstat == G_FS_READ_DIRECTORY_EOD) {
			break;

		} else {
			fprintf(stderr, "failed to read directory\n");
			break;
		}
	}

	g_close_directory(iter);

}
Exemplo n.º 2
0
int main(int argc, char** argv) {

	g_fs_open_directory_status stat;
	char* workdir = new char[G_PATH_MAX];
	g_get_working_directory(workdir);
	auto* iter = g_open_directory_s(workdir, &stat);

	if (stat != G_FS_OPEN_DIRECTORY_SUCCESSFUL) {
		fprintf(stderr, "failed to read directory\n");
		return 1;
	}

	g_fs_directory_entry* entry;
	while (true) {
		g_fs_read_directory_status rstat;
		entry = g_read_directory_s(iter, &rstat);

		if (rstat == G_FS_READ_DIRECTORY_SUCCESSFUL) {
			if (entry == 0) {
				break;
			}

			if (entry->type == G_FS_NODE_TYPE_FILE) {
				printf("   ");
			} else if (entry->type == G_FS_NODE_TYPE_FOLDER) {
				printf(" + ");
			} else {
				printf(" ~ ");
			}
			printf("%s\n", entry->name);
		} else {
			break;
		}
	}

	g_close_directory(iter);

}