Question : Program and method for moving files between drives

I have 4 hard drives of backups of large files.  They are in no order.  I would like to arrange them alphabetically by file name amongst the drives. Only I don't have space to put them all in one location and then sort them out. Is there an automated way or script that would sort and move these files for me.

Thanks,

Answer : Program and method for moving files between drives

Here the example show only how to get the list of the files in separated directories. You can use shutil.copy2() for moving the files to the selected destination (http://docs.python.org/lib/module-shutil.html#l2h-2296). However, sorting is not necessary for the task... unless you want to display the files and let the user choose only some of them.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
import os
 
def myCmp(a, b):
    '''Used for comparison of tuples based on first items.'''
    return cmp(a[0], b[0])
 
 
# The list of backup directories. Here the four drives are simulated in 
# four directories.
dirs = ['c:/tmp/backup1', 'c:/tmp/backup2', 'c:/tmp/backup3', 'c:/tmp/backup4']
 
# Build lst of tuples with bare name and full name. It assumes that all files
# in the directories are backup files. Otherwise, the list must be filtered 
# first.
lst = []
for d in dirs:
    lst.extend( (bare, os.path.join(d, bare)) for bare in os.listdir(d) )
 
# Now sort the list.
lst.sort(myCmp)
 
# Print the sorted bare names plus the full path to the file.
for bare, full in lst:
    print bare, full
Open in New Window Select All
Random Solutions  
 
programming4us programming4us