#include stdio.h | |
#include stdlib.h | |
#include fts.h | |
#include string.h | |
#include sys/stat.h | |
unsigned long get_inode(char *name) { | |
unsigned long inode; | |
struct stat stat_buf; | |
char path[255]; | |
snprintf(path, 255, "./%s", name); | |
if (stat(path, &stat_buf) == 0) { | |
inode = stat_buf.st_ino; | |
return inode; | |
} else { | |
perror("get_inode"); | |
} | |
} | |
int do_move (char *src, unsigned long n) { | |
char cmd[255]; | |
char dest[255]; | |
unsigned long inode1; | |
unsigned long inode2; | |
inode1 = get_inode(src); | |
snprintf(dest, 255, "%sa", src); | |
snprintf(cmd, 255, "%s %s %s", "mv", src, dest); | |
system(cmd); | |
inode2 = get_inode(dest); | |
printf("%lu: %s (%lu) -> %s (%lu)\n", n, src, inode1, dest, inode2); | |
return 0; | |
} | |
int main(int argc, char**argv) { | |
char* paths[] = { "./", NULL }; | |
char *s; | |
FTS *fts; | |
FTSENT *ent; | |
unsigned long n; | |
if (argc > 1) { | |
paths[0] = argv[1]; | |
} | |
n = 1; | |
fts = fts_open(paths, 0, NULL); | |
while ((ent = fts_read(fts)) != NULL) { | |
s = ent->fts_name; | |
if (strcmp("", s) == 0) { | |
continue; | |
} | |
do_move (s, n); | |
n++; | |
} | |
fts_close(fts); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment