So this is a program that's supposed to categorize files into their file types by making new folders.
suppose you run
./category -f path/to/file1.jpg path/to/file2.c path/to/file3.zip
then the ./category
program using -f
will categorise and put all of the files that is right next to -f
into their existing filetypes.
This has something to do with either Threading, Pipes, Sockets but I couldn't figure out which. Regardless, here's my attempt so far. There's a .zip
and after unzipping then I try to attempt to categorise the content.
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
void unzipfiles();
int main(int argc, char **argv) {
pthread_t thread1, thread2;
unzipfiles();
for (int i=0; i < sizeof(argv); i++) {
char *mkdr[3] = {"mkdir", argv[i], NULL};
execv("/usr/bin/mkdir", mkdr);
char *mv[3] = {"mv","-v", "*.$argv", "argv/", argv[i], NULL};
execv("/usr/bin/mv", mv);
}
printf("This line will not be executed\n");
return 0;
}
void unzipfiles() {
char *unzp[3] = {"unzip", "soal3.zip", NULL};
execv("/usr/bin/unzip", unzp);
}
There are no Threading, Pipes, or Sockets that I used above. I couldn't yet grasp the concept of using it
My question is, I know you're supposed to get the file types from argv
, but how?
And what is -f
?
Thank you very much for your answers