<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Akash Senta</title>
    <description>The latest articles on DEV Community by Akash Senta (@akashsenta).</description>
    <link>https://dev.to/akashsenta</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F397636%2Ffad907ce-c179-4cc0-a6e3-cb387de8e1b7.jpeg</url>
      <title>DEV Community: Akash Senta</title>
      <link>https://dev.to/akashsenta</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akashsenta"/>
    <language>en</language>
    <item>
      <title>Python Script to Organize Files in Folders</title>
      <dc:creator>Akash Senta</dc:creator>
      <pubDate>Thu, 21 Jan 2021 04:33:52 +0000</pubDate>
      <link>https://dev.to/akashsenta/python-script-to-organize-files-in-folders-5783</link>
      <guid>https://dev.to/akashsenta/python-script-to-organize-files-in-folders-5783</guid>
      <description>&lt;p&gt;Python is really easy and fun language which can help us to build small scripts to automate some of our work. Here while reading few articles i came across one script written in python that help us to organize files in one folder ex. Downloads Folder where we download everything. To search a particular file from such mess was tedious task, but here my friend python can automate your task and help you to keep organised your downloads directory. Let's go ahead check below script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import os
import shutil

#The Path of the directory to be sorted
path = 'C:\\Users\\&amp;lt;USERNAME&amp;gt;\\Downloads'
#This populates a list with the filenames in the directory
list_ = os.listdir(path)

#Traverses every file
for file_ in list_:
    name,ext = os.path.splitext(file_)
    print(name)
    #Stores the extension type
    ext = ext[1:]
    #If it is directory, it forces the next iteration
    if ext == '':
        continue
    #If a directory with the name 'ext' exists, it moves the file to that directory
    if os.path.exists(path+'/'+ext):
       shutil.move(path+'/'+file_,path+'/'+ext+'/'+file_)
    #If the directory does not exist, it creates a new directory
    else:
        os.makedirs(path+'/'+ext)
        shutil.move(path+'/'+file_,path+'/'+ext+'/'+file_)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can save above mentioned file with organize.py and mentioned Path variable as your Directory which you want to organize in my case i wanted to organize my downloads directory. What this script will do is look for certain extensions in files and make directory with name of extensions of not present and move files in particular directory. Let’s Run file with below command&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fabofvu8ph0bwrvtvjqal.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fabofvu8ph0bwrvtvjqal.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Originally Posted : &lt;a href="http://akashsenta.com/blog/python-script-to-organize-files-in-folder/" rel="noopener noreferrer"&gt;Akash Senta's Blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
