Dec 25, 2016 03:18 PM
(This post was last modified: Dec 26, 2016 11:12 AM by passwords.)
So I was thinking the other day.. I want to code something but I dont know what..
Then I got bored and started sorting files on my desktop and I realized I had ALOT of files and I didnt feel like sorting them all because it would be a boring process of creating folders and adding them all to each and every one.
Then it hit me.. I can create a simple file sorter and share it with other people who might just suffer from the same issue (Cludder Desk)
So here it is.. You simply drag and drop all the files in your desktop and it sorts them into folders i.e .png & .jpg go to Images, .exe files to into Executables etc.
I also commented out the code if anyone wants to use this as a learning project.
Happy coding!
Thanks to Malum & F0RC3FI3LD For helping me understand how to make the code look better!
DO NOT DEAL WITH THIS MEMBER
I looked at him coding this:)
Its a really nice program to learn about files and also just for general use!
Good job:)
(Dec 25, 2016 03:19 PM)ForceJew Wrote: I looked at him coding this:)
Its a really nice program to learn about files and also just for general use!
Good job:)
Thank you! Had a blast doing this :D
things can be done much simple >> shorter << extention
Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP
Dec 25, 2016 04:00 PM
(This post was last modified: Dec 25, 2016 04:01 PM by Zilog80.)
My $0.02:
- The solution name is IMBA 👍
- Why this?
Code if (fileExtension == ".txt")
{
do something here
if (fileExtension == ".txt")
{
Why again the SAME If sentence 'nested' in the SAME condition? do.Ob
}
}
- You should use a reusable 'void', class, helper or other some shit for your folder stuff: The code is a C&P and only change the file extension, so you basically have 20 lines for txt files, the 'same' 20 lines for exe files, other 'same' 20 lines for jpg, same for rars,...
Dec 25, 2016 07:35 PM
(This post was last modified: Dec 25, 2016 08:06 PM by 0xDEAD10CC.)
Why isn't anyone using a Dictionary here? <File Extension, Filepath>. This is the most concrete way of doing this IMO. Keys are already unique.
Code var filemap = Directory.GetFiles(@"...").GroupBy(Path.GetExtension).ToDictionary(x => x.Key, x => x.ToList());
^ Dictionary< string, List<string> >
Code foreach (var kv in filemap)
{
var ext = kv.Key;
/* create folder here (check existence in case?) */
Console.WriteLine(ext);
foreach (var fp in kv.Value)
{
/* move file to designated folder */
Console.WriteLine($"\t- {fp}");
}
}
Dec 26, 2016 06:33 AM
(This post was last modified: Dec 26, 2016 06:49 AM by Snoweyes.)
(Dec 25, 2016 07:35 PM)0xDEAD10CC Wrote: Why isn't anyone using a Dictionary here? <File Extension, Filepath>. This is the most concrete way of doing this IMO. Keys are already unique.
Code var filemap = Directory.GetFiles(@"...").GroupBy(Path.GetExtension).ToDictionary(x => x.Key, x => x.ToList());
^ Dictionary< string, List<string> >
Code foreach (var kv in filemap)
{
var ext = kv.Key;
/* create folder here (check existence in case?) */
Console.WriteLine(ext);
foreach (var fp in kv.Value)
{
/* move file to designated folder */
Console.WriteLine($"\t- {fp}");
}
}
+1
Duplicated code is a code smell. You need to trigger yourself when you write duplicated code and think of a better solution.
(Dec 25, 2016 07:35 PM)0xDEAD10CC Wrote: Code foreach (var kv in filemap)
Console.WriteLine($"\t- {fp}");
Didn't know about $ until now. That's extremely useful! Thanks for the info.
DO NOT DEAL WITH THIS MEMBER
(Dec 26, 2016 07:59 AM)Malum™ Wrote: Didn't know about $ until now. That's extremely useful! Thanks for the info.
It's called String Interpolation and came in C# 6.0 if I am not mistaken.
(Dec 26, 2016 09:33 AM)Ninja Wrote: It's called String Interpolation and came in C# 6.0 if I am not mistaken.
Yea, I had to Google it. Got me going on all the new features and a couple ones I've been missing out on.
Code updated.
Hope you all enjoy!
Dec 26, 2016 02:04 PM
(This post was last modified: Dec 26, 2016 02:06 PM by Zilog80.)
My 2nd $0.02:
- lBox ListBox is useless. You could remove it from your frmMain Form.
- Why you call a class/function 'Sort' if this class/function do not perform any kind of sorting? 😧
- 2nd 'Sort' function in FileSorter class should be private, not public.
- if you throw an exception you should propagate it, if don't do this way your try is useless:
Code In frmMain:
try
Foo();
catch ex
//ex handling
In Helper:
int Foo()
try
Foo2();
catch ex
throw new exception(ex.message);
...
int Foo2()
try
//stuff here
catch ex
throw ex
|