Skip to content

Commit

Permalink
Merge pull request #5 from Shreejan-35/file-folder
Browse files Browse the repository at this point in the history
Entered the function which can rename a folder and find a file or folder
  • Loading branch information
CapedDemon authored Nov 26, 2021
2 parents 41d494c + 328f6dd commit 6e8cb51
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 35 deletions.
Binary file modified CommandConsole.exe
Binary file not shown.
58 changes: 54 additions & 4 deletions MainCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <dirent.h>
#include <unistd.h>
#include <time.h>
#define SIZE 25
#define SIZE 260

char change_dir[100];

Expand Down Expand Up @@ -130,7 +130,7 @@ void clearScreen()
}

// Fucntion to copy file
void copy()
void copy_file()
{
FILE *ptr1;
FILE *ptr2;
Expand Down Expand Up @@ -227,11 +227,13 @@ void help()
printf(">>clr - This will clear the screen of the terminal\n\n");
printf(">>read - This will print the content of the file.\n\n");
printf(">>cnge - This will change your username and password\n\n");
printf(">>copy - This will copy the contents of one file to another file.\n\n");
printf(">>cfile - This will copy the contents of one file to another file.\n\n");
printf(">>sys - This will print the information of your OS.\n\n");
printf(">>echo - This will print anything which you have given. After writing echo press enter then write whatever you want and press enter.\n\n");
printf(">>root - This will print the username and password\n\n");
printf(">>rname - This will rename the file name you want.\n\n");
printf(">>rfile - This will rename the file with the name you want.\n\n");
printf(">>rdr - This will rename the folder with the name you want.\n\n");
printf(">>getf - This will confirm you that the fille or folder name you have given is present in the directory that you specified.\n\n");
}

//function to list all the files in the current directory.
Expand Down Expand Up @@ -489,4 +491,52 @@ void pcwd()
{
printf("%s\n", current_working_dir);
}
}

// Function to rename folder
void renameFolder(){
getchar();
char firstname[SIZE], lastname[SIZE];
printf("Enter the current name of the folder: ");
fgets(firstname, SIZE, stdin);
firstname[strlen(firstname) - 1] = 0;
printf("Enter the new name of the folder: ");
fgets(lastname, SIZE, stdin);
lastname[strlen(lastname) - 1] = 0;

int value = rename(firstname, lastname);
if(!value){
printf("Successfully changed\n");
}
else{
printf("Cannot change\n");
}
}

// Function to find a file or folder in a folder
void getf(){
getchar();
char foldername[SIZE];
printf("Enter the name of the folder or directory first: ");
fgets(foldername, SIZE, stdin);
foldername[strlen(foldername) - 1] = 0;
DIR *dp;
struct dirent *dirp;

if ((dp = opendir(foldername)) == NULL)
{
printf("can't find %s\n", foldername);
}
else{
printf("Enter the filename or foldername to find: ");
char reciepent[SIZE];
fgets(reciepent, SIZE, stdin);
reciepent[strlen(reciepent) - 1] = 0;
while ((dirp = readdir(dp)) != NULL)
{
if (!strcmp(dirp->d_name, reciepent))
printf("%s is presnt in the folder %s\n", dirp->d_name, foldername);
}
}
closedir(dp);
}
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ The main program is written in the main.c file and the functions written there a
- Write something in a file: wrte
- Print the content of the file: read
- Change the username and password: cnge
- Copy the contents of one file to another file: copy
- Copy the contents of one file to another file: cfile
- Print the information of OS: sys
- Print the thing you wanted: echo
- Print username & password: root
- Rename the file: rname
- Rename the file: rfile
- Rename the folder: rdr
- To confirm that a file or folder is present in a directory specified by you: getf

All the functions are written in **MainCommands.h**

Expand Down
69 changes: 40 additions & 29 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ Language: C
#include <string.h>
#include <time.h>


//define variables
#define SIZE 25
#define SIZE 260

void main_loop()
{
Expand All @@ -37,86 +36,98 @@ void main_loop()

else if (strcmp(cmd_str, "cnge") == 0)
{
change(); //calling the change function in the change_root.h
change();
}

else if (strcmp(cmd_str, "help") == 0)
{
help(); //calling the help function in the help_file.h
help();
}
else if (strcmp(cmd_str, "list") == 0)
{
list(); //calling the list function in the list_file.h
list();
}
else if (strcmp(cmd_str, "date") == 0)
{
date(); //calling the date function in the date_file.h
date();
}
else if (strcmp(cmd_str, "calc") == 0)
{
calc(); //calling the calc function in the calc_file.h
calc();
}
else if (strcmp(cmd_str, "pcwd") == 0)
{
pcwd(); //calling the pcwd function in the pcwd_file.h
pcwd();
}
else if (strcmp(cmd_str, "make") == 0)
{
make(); //calling the make function in the make_file.h
make();
}
else if (strcmp(cmd_str, "wrte") == 0)
{
wrte(); //calling the wrte function in the wrte_file.h
wrte();
}
else if (strcmp(cmd_str, "wrta") == 0)
{
wrta(); //calling the wrta function in the wrta_file.h
wrta();
}
else if (strcmp(cmd_str, "remo") == 0)
{
remo(); //calling the remo function in the remo_file.h
remo();
}
else if (strcmp(cmd_str, "ccwd") == 0)
{
ccwd(); //calling the ccwd function in the ccwd_file.h
ccwd();
}
else if (strcmp(cmd_str, "mkdr") == 0)
{
mkdr(); //calling the mkdr function in the file_mkdr1.h
mkdr();
}
else if (strcmp(cmd_str, "rmdr") == 0)
{
rmdr(); //calling the rmdr function in the rmdr_file.h
rmdr();
}
else if (strcmp(cmd_str, "info") == 0)
{
//You can give your name here. And email address.
printf("Developer: Shreejan Dolai\nLanguage: C\nEmail Id: [email protected]\n(c)All rights reserved.\n\n");

printf("\n\n\n\n\n\n");
}
else if (strcmp(cmd_str, "clr") == 0)
{
clearScreen(); //calling the clearScreen function in the clr_file.h
clearScreen();
}
else if (strcmp(cmd_str, "read") == 0)
{
read_file(); //calling the open function in the open_file.h
read_file();
}
else if(strcmp(cmd_str, "copy") == 0){
copy(); //calling the copy fucntion in the copy_file.h
else if (strcmp(cmd_str, "cfile") == 0)
{
copy_file();
}
else if(strcmp(cmd_str, "sys") == 0){
int a = info_system(); //calling the copy fucntion in the system_info.h
else if (strcmp(cmd_str, "sys") == 0)
{
int a = info_system();
}
else if(strcmp(cmd_str, "echo") == 0){
echo(); //calling the echo function in the echo_file.h
else if (strcmp(cmd_str, "echo") == 0)
{
echo();
}
else if(strcmp(cmd_str, "root") == 0){
else if (strcmp(cmd_str, "root") == 0)
{
rootDisplay();
}
else if(strcmp(cmd_str, "rname") == 0){
renameFile(); //calling the renameFile function in the rename_file.h
else if (strcmp(cmd_str, "rfile") == 0)
{
renameFile();
}
else if (strcmp(cmd_str, "rdr") == 0)
{
renameFolder();
}
else if (strcmp(cmd_str, "getf") == 0)
{
getf();
}
else
{
Expand Down Expand Up @@ -157,12 +168,12 @@ int main()

printf("USERNAME:- ");
fgets(username, 10, stdin);
username[strlen(username) -1] = 0;
username[strlen(username) - 1] = 0;

printf("PASSWORD:- ");
fgets(password, 10, stdin);
password[strlen(password) - 1] = 0;

fprintf(w_user, username);
fprintf(wpasswd, password);
fclose(w_user);
Expand Down

0 comments on commit 6e8cb51

Please sign in to comment.