Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void getLSTF(char * path, int socket, char * finalString){
- DIR *dir;
- struct dirent *ent;
- if ((dir = opendir (path)) != NULL) {
- /* print all the files and directories within directory */
- while ((ent = readdir (dir)) != NULL) {
- char filename[PATH_MAX];
- snprintf(filename, sizeof(filename), "%s/%s", path, ent->d_name);
- struct stat st;
- if(stat(filename, &st) == 0 && S_ISREG(st.st_mode))
- pos += sprintf(&finalString[pos], "%s\n", ent->d_name);
- }
- closedir (dir);
- } else {
- /* could not open directory */
- perror (path);
- }
- }
- void getLists(char * path, int socket, bool recursive){
- pos = 0;
- char finalString[PATH_MAX];
- if (recursive == true) {
- getLSTR(path, socket, &finalString);
- write(socket, finalString, pos);
- }
- else {
- getLSTF(path, socket, &finalString);
- write(socket , finalString, pos);
- }
- sprintf(&finalString[pos], '\0');
- }
- /* stampa su stind la lista dei file regolari della cartella in input e delle sue sottocartelle */
- void getLSTR(const char * name, int socket, char * finalString){
- DIR *dir;
- struct dirent *entry;
- if (!(dir = opendir(name)))
- return;
- while ((entry = readdir(dir)) != NULL) {
- if (entry->d_type == DT_DIR) {
- char path[1024];
- if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
- continue;
- snprintf(path, sizeof(path), "%s/%s", name, entry->d_name);
- getLSTR(path, socket, finalString);
- } else {
- //printf("pos: %d file: - %s\n", pos, entry->d_name);
- pos += sprintf(&finalString[pos], "- %s\n", entry->d_name);
- }
- }
- closedir(dir);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement