-1

I am taking backup/sync files in my computer to external harddisk.

for example I sorted some files in my external harddisk like this (I have around 1000 directories and 10000 files, Directory structure below given is for illustrative purpose only)

folderA
    -aa.jpg
    -ab.mp3
    -ac.mp4

folderB
    -ba.jpg
    -bb.mp3
    -bc.mp4

and in my computer I have same files in a folder "temp"

aa.jpg, ab.mp3, ac.mp4, ba.jpg, bb.mp3, bc.mp4

Where I have

I want files in "temp" to be arranged like this

temp

--folderA
    -aa.jpg
    -ab.mp3
    -ac.mp4

--folderB
    -ba.jpg
    -bb.mp3
    -bc.mp4

Is there any tool, or script to do this for me (for 1000+ directories and 10000+ files)?

1 Answers1

0

For Windows create below python script and copy it to the temp dir, just replace the path with your 'temp' :

import os
import shutil

if not os.path.exists('C:/Users/myuser/Desktop/day/folderA'):
       os.makedirs('C:/Users/myuser/Desktop/day/folderA')
if not os.path.exists('C:/Users/myuser/Desktop/day/folderB'):
       os.makedirs('C:/Users/myuser/Desktop/day/folderB')

sourcepath='C:/Users/myuser/Desktop/day'
source = os.listdir(sourcepath)
destinationpath = 'C:/Users/myuser/Desktop/day/folderA'
destinationpath2 = 'C:/Users/myuser/Desktop/day/folderB'
for files in source:
if files.startswith('a'):
    shutil.move(os.path.join(sourcepath,files), os.path.join(destinationpath,files))
if files.startswith('b'):
    shutil.move(os.path.join(sourcepath,files), os.path.join(destinationpath2,files))

listA = os.listdir('C:/Users/myuser/Desktop/day/folderA')
listA.sort()
listB = os.listdir('C:/Users/myuser/Desktop/day/folderB')
listB.sort()
moni
  • 16
  • 4