Imagine a situation like this:You have a folder containing files of multiple types like txt, mp3 etc. You decide to clean up this mess and organize them in a way that images are in one folder and songs in another. Will you be moving them as per file type, i.e. number of moves = number of files . No, I’ll not be doing this :).
This task could be automated by writing this python script which can automatically create a separate directory and move files in their respective destinations.
Please note that you need to setup Python 2 on your system.The script makes use of the module named os which allows us to use OS-specific functionalities.Please note that you need to setup Python on your system before all this can be done. For that, follow these steps:
1) Download the Python from here; https://www.python.org/downloads/
(I’ll prefer 2.7 as it’s a stable build)
2) Install it. Go to C:( where windows reside and Get the path to your python folder (It’ll be something like C:\Python27)
3) Go to My computer (or This pc), go to advanced system settings, search for a variable path there and click on edit.
4) A box will appear with path, scroll the cursor to the already existing path till the end and add ;C:\Python27 (i.e. ; and then the path to your python folder in C drive).
5) Click Save or OK. Create a folder with name Pyprog(or anything else) in your C:\, here we’ll be storing all our python programs, open cmd and type cd C:\Pyprog and then for running a file called first.py (same every python program with an extension .py), run python first.py.
Python code Direct link – https://ide.geeksforgeeks.org/9bY2Mm
Notice in the above image, two new folders named Images and Songs are created on executing the script and the files with mps and jpg extensions are now inside the requireds
Please note the paths mentioned in the above post are according to a general system, you should change paths according to our requirements and do the classification, but the important point is then changing the current working directory which is done using os.chdir(). Also, more if statements can be added pertaining to different file types.
About the author: Ekta is a very active contributor on Geeksforgeeks. Currently studying at Delhi Technological University.She has also made a Chrome extention for www.geeksquiz.com to practise mcqs randomly.She can be reached at github.com/Ekta1994
If you also wish to showcase your blog here, please see GBlog for guest blog writing on GeeksforGeeks.
- Automating a Google Form Filling Task Using UiPath
- Don't Let Your Geographical Location Be A Barrier In Your Success - Live Classes By GeeksforGeeks
- Windows Server 2012 R2 Stuck at "Updating Your System”
- Difference between FAT32, exFAT, and NTFS File System
- Is your Web Application Secure Enough? Think Again
- Making your WordPress Website More Secure
- How to write a good SRS for your Project
- Making your first Open Source Pull Request | Github
- 8 Ways to Shipwreck Your Next Website Design
- How can You Boost Your Career to the Next Level?
- How to create and deploy your portfolio in under 10 minutes
- Do you want to make your own games?
- 10 Tips to Protect Your Online Data Privacy in 2019
- Learn with GeeksforGeeks Course - Best Courses To Land Job In Your Dream Company
- Deploying Your Web App using Azure App Service
- Switch Your Career to Machine Learning - A Complete Guide
- Should You Connect Your Devices to Free Wi-Fi?
- What was your GATE (CSE) preparation story?
- Get Ahead of Your Peers With GeeksforGeeks's Live Courses