Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void cmdList(){
- char ruta[PATH_MAX];
- int flagHid=0,flagLong=0, flagAcc=0, flagReca=0, flagRecb=0; //flags para detectar las opciones que se pasan
- DIR *d;
- struct dirent *dirent;
- getcwd(ruta, PATH_MAX);
- strcat(ruta, "/");
- strcat(ruta, trozos[numtrozos-1]);
- if(numtrozos==1)
- cmdCarpeta();
- if(numtrozos==2){
- if((d=opendir(ruta)) == NULL){perror("opendir"); return;}
- printf("************%s\n",trozos[numtrozos-1]);
- while((dirent = readdir(d))!= NULL){
- if(dirent->d_name[0] != '.'){
- printf("%s\n", dirent->d_name);
- }
- }
- }
- if(numtrozos>2){
- //Obtenemos los flags que se pasan
- for(int i = 1; i < numtrozos && trozos[i][0] == '-' ; i++){
- if(strcmp(trozos[i],"-hid")==0) flagHid = 1;
- else if(strcmp(trozos[i], "-long") == 0) flagLong = 1;
- else if(strcmp(trozos[i], "-acc") == 0) flagAcc = 1;
- else if(strcmp(trozos[i], "-reca") == 0) flagReca = 1;
- else if(strcmp(trozos[i], "-recb") == 0) flagRecb = 1;
- }
- if((d=opendir(ruta)) == NULL){perror("opendir"); return;}
- if(flagAcc==1 && flagLong==0 && flagHid==0){
- printf("************%s\n",trozos[numtrozos-1]);
- while((dirent = readdir(d))!= NULL){
- if(dirent->d_name[0] != '.'){
- cmdStat2(dirent->d_name,0,1,ruta,0);
- }
- }
- }
- if(flagAcc==1 && flagLong==0 && flagHid==1){
- printf("************%s\n",trozos[numtrozos-1]);
- while((dirent = readdir(d))!= NULL){
- cmdStat2(dirent->d_name,0,1,ruta,0);
- }
- }
- if(flagHid==1 && flagLong==0 && flagAcc==0 && flagReca==0 && flagRecb==0){
- printf("************%s\n",trozos[numtrozos-1]);
- while((dirent = readdir(d))!= NULL){
- printf("%s\n", dirent->d_name);
- }
- }
- if(flagLong==1 && flagHid == 0 && flagAcc==0 && flagReca==0 && flagRecb==0){
- printf("************%s\n",trozos[numtrozos-1]);
- while((dirent = readdir(d))!= NULL){
- if(dirent->d_name[0] != '.'){
- cmdStat2(dirent->d_name,1,0,ruta,0);
- }
- }
- }
- if(flagLong==1 && flagHid == 1 && flagReca ==0 && flagRecb==0){
- printf("************%s\n",trozos[numtrozos-1]);
- while((dirent = readdir(d))!= NULL){
- cmdStat2(dirent->d_name,1,0,ruta,0);
- }
- }
- if(flagReca==1){
- cmdListaREC(trozos[numtrozos-1],0,flagHid, flagLong);
- }else if(flagRecb==1){
- cmdListaREC(trozos[numtrozos-1],1,flagHid, flagLong);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement