This project presents the design and implementation of a file management or explorer system in Java, utilizing a tree data structure to represent hierarchical directory structures. The system comprises two primary classes: File
and Folder
, encapsulated within a FileExplorerElement
superclass to ensure polymorphic behavior. The Folder
class serves as a tree node, containing a list of FileExplorerElement
objects as its children, thus enabling the representation of directories containing both files and subdirectories.
- Develop a functional file explorer with a user-friendly GUI.
- Implement essential file operations such as create, delete, and move.
- Ensure accurate display of directory structures.
- Provide a CLI for advanced users.
- Optimize the application for performance.
- Directory: Manages the directory structure and file operations.
- Folder: Represents a storage container for files and other folders. Folders make up the directory and are the reason for the implementation of a tree data structure.
- File: Represents files.
- FileExplorerElement: Base class for files and folders.
- FileExplorer: Main GUI application class.
- Main: CLI interface for the file explorer.
- Directory: Contains methods for creating, deleting, moving files and directories, and displaying the directory structure.
- Folder: Extends
FileExplorerElement
, representing directories. - File: Extends
FileExplorerElement
, representing files. - FileExplorer: Implements the GUI using Java Swing, providing an interface for users to interact with the file system.
- Main: Provides a CLI interface for file operations.
- Tree Structure: Used to represent the file and directory hierarchy, enabling efficient traversal and management. It was chosen because of the hierarchical nature of file management systems.
- ArrayList: Used to store the contents of directories, allowing dynamic resizing and easy access.
- Depth-First Search (DFS): Used for displaying the directory structure and searching files.
- Sorting Algorithm: Custom sorting is implemented to sort files and directories based on various attributes (e.g. name, item type, size, date modified).
- File and Directory Creation: O(n), where n is the number of directories in the path.
- File and Directory Deletion: O(n), where n is the number of elements in the directory.
- Directory Display: O(n), where n is the total number of files and directories.
- Sort: O(n log n), where n is the total number of files and directories.
- Search: O(n), where n is the total number of files and directories.
- Efficient use of data structures like
ArrayList
and Trees for managing file and directory operations. - Recursive algorithms for displaying and traversing directories to minimize code complexity.
- Solution: Modified the recursive method to properly indent directory levels using a multiplier for spaces.
- Solution: Enhanced the
createFile
method to navigate through the directory path and create the file at the correct location.
- Solution: Introduced try-catch blocks across all methods to handle exceptions and provide meaningful error messages.
- Solution: Seamlessly integrated file operations with the GUI, ensuring user inputs are correctly handled and reflected in the file system.
- Compile and run the
FileExplorer.java
file. - Use the provided GUI to create, delete, move files and directories, and view the directory structure.
- Compile and run the
Main.java
file. - Enter commands as per the CLI instructions to perform file operations.
create_file <file_path>
: Create a new file at the specified path.create_dir <dir_path>
: Create a new directory at the specified path.delete <path>
: Delete the file or directory at the specified path.move <source_path> <destination_path>
: Move a file or directory from the source path to the destination path.search <attribute> <value>
: Search for files or directories based on a specified attribute and value.sort <attribute>
: Sort files and directories by the specified attribute.show_structure
: Display the current directory and file structure in a tree format.