Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,28 @@ Downloads/
| |-- file6.unknown
```

************************************************************************************************************************************************************

## **Let's take about the algorithm:**

we can divide the algorithm of the script into 4 parts:

- Geting the path of the directory we wnat to organize.
- Creating the sub-directories to organize the files and put them inside the sub-directories.
- Organize the files and put them inside the sub-directories.
- List the sub-directories and the files as a way of verfication to make sure that the algorithm is working as required.

To-do that, I create four functions for each part:

- GetPath
- MK_DIRS
- OrganizeFiles
- LS_DIRS

## **The design:**

![image](https://github.com/Ali-Elbana/M1-A2/assets/97269796/0d6e38f5-ef6e-4f29-bb02-ca72478ac794)




## How to upload task on github.
- Please refer to explanation video that has been sent through email.
99 changes: 0 additions & 99 deletions file_organizer.sh

This file was deleted.

75 changes: 75 additions & 0 deletions student-solution.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

DIR_PATH=""

GetPath()
{
read -p "Enter the path: " DIR_PATH
}

MK_DIRS()
{
cd ${DIR_PATH}

DIRS=( "txt" "jpg" "pdf" "misc" )

# if the directory not found create it #
for DIR in "${DIRS[@]}" ; do

if [[ ! -d "$DIR" ]] ; then
mkdir "$DIR"
fi

done
}

OrganizeFiles()
{
for file in "$DIR_PATH"/* ; do

# if the file is a directory skip it #
if [[ -d "$file" ]] ; then
continue
fi

if [[ "$file" == *.txt ]] ; then
mv "$file" "$DIR_PATH"/txt

elif [[ "$file" == *.jpg ]] ; then
mv "$file" "$DIR_PATH"/jpg

elif [[ "$file" == *.pdf ]] ; then
mv "$file" "$DIR_PATH"/pdf

else
mv "$file" "$DIR_PATH"/misc
fi

done
}

LS_DIRS()
{

ls $DIR_PATH $DIR_PATH/txt $DIR_PATH/pdf $DIR_PATH/jpg $DIR_PATH/misc

}

GetPath $DIR_PATH

MK_DIRS $DIR_PATH

OrganizeFiles $DIR_PATH

LS_DIRS $DIR_PATH











1 change: 0 additions & 1 deletion student_solution.sh

This file was deleted.