Computer Editing File Collection Program Construction

in utopian-io •  7 years ago  (edited)

I prepared a program that would make a lot of work for you today.

What is the benefit of this program? and what does it do .

If you are using an irregular desktop like me or you are distributing everything, this program will help you collect your scattered pictures, music files, office files, video clips, compressed files and more in separate folders within 1 second.
The main purpose of this program is to save you time ensure that you have a clean and comfortable computer.
If you encounter an error or something goes wrong, you can comment, i am happy to assist you.

GitHub : https://github.com/ShanksTaicho/Computer-Editing

Project Codes : https://github.com/ShanksTaicho/Computer-Editing/blob/master/Codes

Readme.md : https://github.com/ShanksTaicho/Computer-Editing/blob/master/README.md

I hope it is useful for you, I tried to get to introduce my program and clarify which codes are used. If you have a problem or suggestions somewhere, please comment.

Features;

1 - Image Files = ".jpg.jpeg.png.ico.gif.bmp.ai.psd"
2 - Musics Files = ".mp3.mp4.au.mpg.mpeg"
3 - Videos Files = ".avi.flv.mov.qt"
4 - Programs Files = ".exe.bat.com"
5 - Web Files = "".html.htm.aspx.php.css.jsp.js"
6 - Compressed Files = ".rar.zip.iso.arc.cab"
7 - Office Files = ".xls.xlsx.doc.docx.md5.accdb.txt.pps.pdf.log.bak.bat.dll.ttf"
8 - Shortcuts = ".lnk"


Desing ;

ToolBox : 2 Button , 2 groupBox , 9 checkBox


Let's start coding now

We first recognize our class and then our global variables.

using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using ComputerEditing.Properties;

string[] folderNames = { "Folders", "Pictures", "Musics", "Videos",   "Programs",
   "Web Files", "Compressed Files", "Office Files", "Shortcuts" };

string[] extensions = { "", ".jpg.jpeg.png.ico.gif.bmp.ai.psd", ".mp3.mp4.au.mpg.mpeg", ".avi.flv.mov.qt", ".exe.bat.com", 
 ".html.htm.aspx.php.css.jsp.js", ".rar.zip.iso.arc.cab", 
 ".xls.xlsx.doc.docx.md5.accdb.txt.pps.pdf.log.bak.bat.dll.ttf", ".lnk" };

We now use the codes necessary to select the part we want to edit.

With the help of the FolderBrowserDialog object we allow the user to select a folder.

private void button1_Click(object sender, EventArgs e)
    {
        FolderBrowserDialog gs = new FolderBrowserDialog();
        gs.ShowDialog();
        if (gs.SelectedPath != "")
        {
            txtPath.Text = gs.SelectedPath;
        }
        else
        {
            MessageBox.Show("Select Folder.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }

Then we add the codes that will do the correction

private void btnKlasorle_Click(object sender, EventArgs e)
    {
        if (txtPath.Text != "")
        {
            string path = txtPath.Text;
            string[] folders = Directory.GetFiles(path);

            foreach (CheckBox item in groupBox2.Controls)
            {
                if (item.Checked)
                {
                    string fileName = item.Text;
                    int fileNameIndex = 0;
                    for (int a = 0; a < folderNames.Length; a++)
                    {
                        if (folderNames[a].ToString() == fileName)
                        {
                            fileNameIndex = a;
                        }
                    }
                    string extension = extensions[fileNameIndex].ToString();

                    for (int a = 0; a < folders.Length; a++)
                    {
                        if (fileName != "Folders")
                        {
                            string namee = "";
                            try
                            {
                                int lastPointIndex = folders[a].ToString().LastIndexOf(".");
                                string DynFileExtension = folders[a].ToString().Substring(lastPointIndex,
                                                                  folders[a].ToString().Length - lastPointIndex);
                                if (extension.Contains(DynFileExtension))
                                {
                                    if (!Directory.Exists(path + "\\" + fileName))
                                    {
                                        Directory.CreateDirectory(path + "\\" + fileName);
                                    }
                                    int lastSlamIndex = folders[a].ToString().LastIndexOf(@"\");
                                    namee = folders[a].ToString().Substring(lastSlamIndex,
                                                                    folders[a].ToString().Length - lastSlamIndex);
                                    File.Move(folders[a].ToString(), path + "\\" + fileName + "\\" + namee);
                                }
                            }
                            catch (Exception)
                            {
                                errCondition = 1;
                            }
                        }
                        else
                        {
                            string[] folderss = Directory.GetDirectories(path);
                            string fileNamee = "";
                            for (int b = 0; b < folderss.Length; b++)
                            {
                                try
                                {
                                    string filePath = folderss[b].ToString();
                                    int lastSlaj = filePath.LastIndexOf(@"\");
                                    fileNamee = filePath.Substring(lastSlaj, folderss[b].ToString().Length
                                                                                                            - lastSlaj);
                                    string folderUnnamedPath = filePath.Substring(0, filePath.Length
                                                                                                  - fileNamee.Length);
                                    string lastPath = folderUnnamedPath + "\\Folders" + fileNamee;
                                    if (!fileNamee.Contains("Folders"))
                                    {
                                        if (!Directory.Exists(path + "\\" + fileName))
                                        {
                                            Directory.CreateDirectory(path + "\\" + fileName);
                                        }
                                        Directory.Move(filePath, lastPath);
                                    }
                                }
                                catch (Exception)
                                {
                                    errCondition = 1;
                                }
                            }
                        }
                    }
                }
            }
        }
        else
        {
            MessageBox.Show("Select Path", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        if (errCondition == 1)
        {
            MessageBox.Show("Some running applications have not moved. Try again after closing the applications.",
                                                                "Information", MessageBoxButtons.OK,MessageBoxIcon.Information);
        }
    }   

Result and Test ;

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

The @OriginalWorks bot has determined this post by @shankstaicho to be original material and upvoted it!

ezgif.com-resize.gif

To call @OriginalWorks, simply reply to any post with @originalworks or !originalworks in your message!

Your contribution cannot be approved because it does not refer to or relate to an open-source repository. See here for a definition of "open-source."

  • Microsoft Visual Studio is not open source.

You can contact us on Discord.
[utopian-moderator]