Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace File_Browser
- {
- public partial class Form1 : Form
- {
- string drive;
- public Form1()
- {
- InitializeComponent();
- }
- private void getDriveInfoButton_Click(object sender, EventArgs e)
- {
- drivesListBox.Items.Clear();
- drivesListBox.Items.Add("====Drives Info====");
- DriveInfo[] drives = DriveInfo.GetDrives();
- foreach(DriveInfo drive in drives)
- {
- if (!drive.IsReady) continue;
- drivesListBox.Items.Add(drive.Name + "\t" + drive.TotalSize / 1024.0f / 1024 / 1024 + " GB");
- }
- }
- private void drivesListBox_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (drivesListBox.SelectedItem == null) return;
- string temp = drivesListBox.SelectedItem.ToString().Substring(0, 3);
- if (!Environment.GetLogicalDrives().Contains(temp)) return;
- drive = temp;
- listFolders(new DirectoryInfo(drive));
- pathLabel.Text = drive;
- }
- private void listFolders(DirectoryInfo directory)
- {
- foldersListBox.Items.Clear();
- DirectoryInfo[] folders = directory.GetDirectories();
- foreach(DirectoryInfo folder in folders)
- {
- if (folder.Attributes.HasFlag(FileAttributes.Hidden)) continue;
- foldersListBox.Items.Add(folder.Name);
- }
- FileInfo[] files = directory.GetFiles();
- foreach(FileInfo file in files)
- {
- if (file.Attributes.HasFlag(FileAttributes.Hidden)) continue;
- foldersListBox.Items.Add(file.Name);
- }
- }
- private void foldersListBox_DoubleClick(object sender, EventArgs e)
- {
- if (foldersListBox.SelectedItem == null) return;
- string folder = foldersListBox.SelectedItem.ToString();
- if (new DirectoryInfo(pathLabel.Text + folder).Attributes.HasFlag(FileAttributes.Directory))
- {
- pathLabel.Text = pathLabel.Text + folder + @"\";
- listFolders(new DirectoryInfo(pathLabel.Text));
- } else {
- string temp = pathLabel.Text + folder;
- if (temp.Contains(".txt"))
- {
- TextEditor textEditorForm = new TextEditor();
- textEditorForm.Show();
- textEditorForm.loadTextEditor(temp);
- } else
- {
- System.Diagnostics.Process.Start(temp);
- }
- }
- }
- private void backButton_Click(object sender, EventArgs e)
- {
- if(pathLabel.Text != drive && pathLabel.Text != "N/A"){
- string location = pathLabel.Text.Substring(0, pathLabel.Text.Length - 1);
- location = location.Substring(0, location.LastIndexOf(@"\") + 1);
- listFolders(new DirectoryInfo(location));
- pathLabel.Text = location;
- }
- }
- private void newFolderButton_Click(object sender, EventArgs e)
- {
- if (String.IsNullOrEmpty(drive) && pathLabel.Text == "N/A") return;
- string name = Microsoft.VisualBasic.Interaction.InputBox("Enter Folder Name", "Creating New Folder", "New Folder");
- if (String.IsNullOrEmpty(name)) return;
- if (Directory.Exists(pathLabel.Text + name)) return;
- try {
- Directory.CreateDirectory(pathLabel.Text + name);
- } catch(Exception ex) {
- MessageBox.Show(ex.Message);
- }
- listFolders(new DirectoryInfo(pathLabel.Text));
- }
- private void deleteButton_Click(object sender, EventArgs e)
- {
- if (foldersListBox.SelectedItem == null) return;
- if (MessageBox.Show("Are you sure? You will delete: " + pathLabel.Text + foldersListBox.SelectedItem.ToString(), "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) {
- if(new DirectoryInfo(pathLabel.Text + foldersListBox.SelectedItem).Attributes.HasFlag(FileAttributes.Directory)){
- Directory.Delete(pathLabel.Text + foldersListBox.SelectedItem, true);
- } else{
- File.Delete(pathLabel.Text + foldersListBox.SelectedItem);
- }
- listFolders(new DirectoryInfo(pathLabel.Text));
- }
- }
- private void newTextFileButton_Click(object sender, EventArgs e)
- {
- if (String.IsNullOrEmpty(drive) && pathLabel.Text == "N/A") return;
- string name = Microsoft.VisualBasic.Interaction.InputBox("Enter Text File Name", "Creating New Text File", "New Text File");
- if (String.IsNullOrEmpty(name)) return;
- string temp = pathLabel.Text + name;
- if (!temp.Contains(".txt")) temp += ".txt";
- if (File.Exists(temp)) return;
- try
- {
- File.CreateText(temp).Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- listFolders(new DirectoryInfo(pathLabel.Text));
- TextEditor textEditorForm = new TextEditor();
- textEditorForm.Show();
- textEditorForm.loadTextEditor(temp);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement