C Project : Sort files into folders by extension

I developed a mini project using C which can be used to sort files in a cluttered directory to different folders. The program deals with the main types of files we commonly deal with like pictures, videos, music & documents. The program lets you name the folders where you want to move different types of files. The program uses Windows commands so it is only compatible for Windows operating system. Let's call it Sort 2 Folder.

Sort 2 Folder
 

Working

The C program does not need any external header files to run. 
The header files needed are stdio.h, stdlib.h and string.h
Character 2D array a[4][20] stores the name of the folders, there are a total of 4 folders to be created and the folder names can have up to 20 characters.
The creation of folder and moving of files are done by system() in C
For creation folders windows command mkdir "<file name>" is used in system().

sprintf(buffer,"mkdir \"%s\"",a[i]);
        system(buffer)
;

In the above code buffer is a character array which is predefined sprintf stores or prints the system command "mkdir \"%s\"",a[i] into buffer array and later called system() with buffer as an argument.

The same process is happening when sorting and moving files to these folders, the changes are, we use the system command to move files by their extension.

sprintf(buffer, "move *.png \"%s\"", a[i]);
          system(buffer);
 
  
Here move command moves files with extension .png to a[i], which indicates the folder name.

C program source code

 #include <stdlib.h>  
 #include <stdio.h>  
 #include <string.h>  
 void main()  
 {  
   const int folder = 4;  
   char a[4][20];  
   strcpy(a[0],"Images");  
   strcpy(a[1],"Videos");  
   strcpy(a[2],"Docs");  
   strcpy(a[3],"Music");  
   char buffer[100];  
   int i = 0;  
   for (; i < folder; ++i)  
   {  
     printf("\nFolder Name for %s: ",a[i]);  
     gets(a[i]);  
     sprintf(buffer,"mkdir \"%s\"",a[i]);  
     system(buffer);  
     if(i==0)  
     {  
       sprintf(buffer, "move *.ico \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.jpeg \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.png \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.tif \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.tiff \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.bmp \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.eps \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.jpg \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.raw \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.cr2 \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.nef \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.orf \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.sr2 \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.indd \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.ai \"%s\"", a[i]);  
       system(buffer);  
       system("cls");  
     }  
     else if(i==1)  
     {  
       sprintf(buffer, "move *.avi \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.flv \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.3gp \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.mpg \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *mpeg \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.wmv \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.mov \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.ogg \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.webm \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.mkv \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.ogv \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.vob \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.gifv \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.gif \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.mng \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.asf \"%s\"", a[i]);  
       system(buffer);  
       system("cls");  
     }  
     else if(i==2)  
     {  
       sprintf(buffer, "move *.doc \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.docx \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.ppt \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.pptx \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.pps \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.key \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.pdf \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.odt \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.rtf \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.tex \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.wps \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.wpd \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.zip \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.rar \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.sql \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.xml \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.apk \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.exe \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *com \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.bat \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.py \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.bin \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.c \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.js \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.cpp \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.gadget \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.class \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.java \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.cs \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.h \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.swift \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.vb \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.ods \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.xlr \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.xls \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.xlsx \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.bak \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.tmp \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.ini \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.cpl \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.dmp \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.1st \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.ans \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.ascii \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.bib \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.chord \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.dmp \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.dropbox \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.readme \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.emlx \"%s\"", a[i]);  
       system(buffer);  
       system("cls");  
     }  
     else if(i==3)  
     {  
       sprintf(buffer, "move *.3ga \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.4mp \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.5xb \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.5xe \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.669 \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.a2b \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.aa \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.aa3 \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.aax \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.abc \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.ac3 \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.acp \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.aiff \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.all \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.aob \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.bwf \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.cda \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.cel \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.cpr \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.dcm \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.dmsa \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.dss \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.dtm \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.f64 \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.flac \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.gp5 \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.hca \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.iff \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.iti \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.kar \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.m3u \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.m4r \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.m5p \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.mdc \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.mid \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.mka \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.mmf \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.mp3 \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.mpu \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.mxl \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.nkc \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.pca \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.pcg \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.pek \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.ra \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.raw \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.rgrp \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.rmj \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.rti \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.slp \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.vlc \"%s\"", a[i]);  
       system(buffer);  
       sprintf(buffer, "move *.zvd \"%s\"", a[i]);  
       system(buffer);  
       system("cls");  
     }  
   }  
   printf("  SORTION COMPLETED 100%");  
 } 

Copy and paste the above code to IDE, compile and run the program. Now you will get the .exe file of the program which you can copy to any directory where you want to sort and run the .exe in that directory. 

So this is an easy micro or mini project using C and with basic knowledge in C++, this can also be programmed in C++ by making some minute changes since most of the functions and syntax are almost the same.
C Project : Sort files into folders by extension C Project : Sort files into folders by extension Reviewed by Jobin Jose on May 30, 2019 Rating: 5

2 comments:

  1. Didn’t work for me, had to contact @technician.ig on Instagram to lift the block

    ReplyDelete

Powered by Blogger.