accounting for files "." and ".."
This commit is contained in:
@ -38,6 +38,10 @@ unsigned long get_dir_size(char *path){
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
|
||||
/* removes files "." and ".." */
|
||||
entry_count -= 2;
|
||||
}
|
||||
return entry_count;
|
||||
|
||||
}
|
||||
@ -45,7 +49,7 @@ unsigned long get_dir_size(char *path){
|
||||
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content){
|
||||
struct dirent **entry;
|
||||
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */
|
||||
scandir(path, &entry, NULL, alphasort);
|
||||
scandir(path, &entry, skip_dot, alphasort);
|
||||
} else {
|
||||
scandir(path, &entry, skip_hidden_files, alphasort);
|
||||
}
|
||||
|
15
sorting.c
15
sorting.c
@ -2,6 +2,7 @@
|
||||
#include <dirent.h>
|
||||
#include <strings.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "defines.h"
|
||||
|
||||
extern unsigned int settings;
|
||||
@ -13,6 +14,12 @@ int skip_hidden_files(const struct dirent *entry){
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
int skip_dot(const struct dirent *entry){
|
||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int sort_natural(const void *file0, const void *file1){
|
||||
unsigned char file_type0 = ((file*)file0)->file_type;
|
||||
@ -49,8 +56,6 @@ int sort_alpha(const void *file0, const void *file1){
|
||||
int sort_random(const void *file0, const void *file1){
|
||||
unsigned char file_type0 = ((file*)file0)->file_type;
|
||||
unsigned char file_type1 = ((file*)file1)->file_type;
|
||||
char *file_name0 = ((file*)file0)->file_name;
|
||||
char *file_name1 = ((file*)file1)->file_name;
|
||||
static int seed = 0;
|
||||
static int random = 0;
|
||||
|
||||
@ -60,9 +65,6 @@ int sort_random(const void *file0, const void *file1){
|
||||
if (random == 0) {
|
||||
random = seed;
|
||||
}
|
||||
if (strcmp(file_name0, ".") == 0 || strcmp(file_name0, "..") == 0) {
|
||||
return -1;
|
||||
}
|
||||
char weight = 0;
|
||||
if (file_type0 == FILE_TYPE_DIR || file_type0 == FILE_TYPE_SYMLINK) {
|
||||
weight |= 1;
|
||||
@ -129,9 +131,6 @@ int sort_size(const void *file0, const void *file1){
|
||||
unsigned long file_size1 = ((file*)file1)->file_size;
|
||||
char *file_name0 = ((file*)file0)->file_name;
|
||||
char *file_name1 = ((file*)file1)->file_name;
|
||||
if (strcmp(file_name0, ".") == 0 || strcmp(file_name0, "..") == 0) {
|
||||
return -1;
|
||||
}
|
||||
if (file_type0 == file_type1) {
|
||||
if (file_size0 > file_size1) {
|
||||
return -1;
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include "sorting.c"
|
||||
#endif
|
||||
|
||||
int skip_hidden_files(const struct dirent *entry);
|
||||
int skip_dot(const struct dirent *entry);
|
||||
void sort_dir(unsigned long *dir_length_width, char *dir_content);
|
||||
void sort_dir(unsigned long *dir_length_width, char *dir_content);
|
||||
int sort_natural(const void *file0, const void *file1);
|
||||
|
Reference in New Issue
Block a user