90 Snippets: Organizing Files with shell! ๐Ÿ“‚โœจ

90 Snippets: Organizing Files with shell! ๐Ÿ“‚โœจ

90 Projects towards mastery - Day 01 ๐Ÿš€

ยท

3 min read

Hey, tech wizards! Astro here, and I've got something super cool to share with you today. Remember my "90 Snippets" challenge? Well, I just wrapped up Day 01 in Shell Scripting, and boy, did I create some file-organizing magic! ๐Ÿš€๐Ÿ”ฎ

The Challenge

Create a script that takes a directory as input and organizes its files into subdirectories based on their file extensions (e.g., move all ".txt" files to a "txt" folder).

Bonus: Let the script take a file extension as an argument and use it to only organize files of that specific extension

Solution: This magical link will take you there ๐Ÿฆ„

Introducing "fileorg.sh" - A Magical File Organizer! ๐ŸŽฉ๐Ÿช„

So, here's the deal: I built this script called "fileorg.sh," and it's like a genie that organizes files inside directories, all based on their extensions! No more messy file cabinets in my directories - neat and tidy, just the way I like it! ๐Ÿ’โ€โ™‚๏ธ

Here's how "fileorg.sh" works its magic:

I. Running the Script

Get Ready for the Magic Words! ๐Ÿง™โ€โ™‚๏ธTo get the party started, all you need to do is run the script with three simple parameters: the directory you want to organize, the name of the new directory where everything will be sorted, and an optional extension parameter (if you want to organize only specific file types). Easy peasy, right?

./fileorg [dir] [new_dir] [ext]

II. Displaying Help

When You Need a Little Assistance! ๐Ÿ†˜Not sure how to use the magical "fileorg.sh"? Don't worry! I've got you covered with a helpful "help" function. Just type:

./fileorg -h

And voilร ! The script will show you everything you need to know. No spells or magic wands are required! ๐Ÿช„

Organizing Files: The Magic Unfolds! ๐Ÿช„๐Ÿ”ฅ

Here's where the real magic happens! The script will scan the specified directory and sort all the files according to their extensions, moving them into their respective folders in the new directory.

If you provided an extension parameter, only files with that specific extension will be organized. But wait, there's more! If you didn't provide an extension, "fileorg.sh" will cleverly sort all the files into separate folders based on their extensions. It's like having a file-fairy sprinkling magic dust on your directories! โœจ

But what if the new directory already exists? Fear not, for our script is wise! It won't mess with the existing content; it'll gracefully use the existing directory without affecting anything. See, magic can be practical too! ๐Ÿ˜‰

Leveling Up: Going Beyond the Basics! ๐Ÿ“š๐Ÿ“ˆ

On Day 01, I learned about function magic! I crafted special spells, like "single_ext" and "copy_files," to make my script more powerful and efficient. Each function worked its charm on the files, ensuring they were sorted into their rightful places.

It's like building a magical arsenal, with each spell getting stronger and more versatile. Who knew organizing files could be this enchanting? ๐Ÿ”๐Ÿ’ป

Conclusion: The Magic Continues! ๐ŸŒŸ๐Ÿ”ฎ

I can't believe how much fun I'm having on this "90 Snippets" journey. With "fileorg.sh" in my arsenal, I'm ready to conquer file chaos and bring order to my directories!

So, my fellow tech enthusiasts, let's keep the magic alive! Embrace challenges, learn new spells, and unravel the mysteries of coding. By Thor, by Odin, we're on our way to becoming tech superheroes! ๐Ÿฆธโ€โ™‚๏ธ๐Ÿ’ฅ

Stay tuned for more enchanting adventures as I dive deeper into the world of coding and take on new challenges in the days to come.

Until next time, keep coding, keep dreaming, and keep your hands dirty (coding ofc +_+)! ๐Ÿš€โœจ

ย