Solved

Program and method for moving files between drives

Posted on 2007-11-14
5
362 Views
Last Modified: 2012-06-22
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,
0
Comment
Question by:mgjust
5 Comments
 
LVL 17

Assisted Solution

by:ramrom
ramrom earned 20 total points
ID: 20286901
Why? What advantage do you get from doing this? Beware that you could get trapped in a situation where a very large file might not fit at the end of drive 1, thus forcing it to drive 2 and leaving a big unused space on drive 1.

How much drive space is there and how much space do the files take up?

Would it not be better to maintain a directory of all files in alphabetic order rather than physically sorting them?

And is this a static backup, or are files added/deleted from time to time.
0
 

Author Comment

by:mgjust
ID: 20286991
Its not static.
The advantage would be to find said files easily.

Is there an easy way to create a directory?
Thanks,
0
 
LVL 15

Expert Comment

by:efn
ID: 20287183
Assuming the number of files is not too huge, it would certainly be possible to write a script that would create an alphabetical index of the files.  I don't know of any off-the-shelf solution.
0
 
LVL 29

Accepted Solution

by:
pepr earned 410 total points
ID: 20287500
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.
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

0
 
LVL 29

Assisted Solution

by:pepr
pepr earned 410 total points
ID: 20287531
The easy way of making the directory that does not exist is:

    os.mkdir(path)

or
 
    os.makedirs(path)         # makes also upper subdirectories if they do not exist

See http://docs.python.org/lib/os-file-dir.html#l2h-2688 
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Create your own, high-performance VM backup appliance by installing NAKIVO Backup & Replication directly onto a Synology NAS!
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question