Solved

Program and method for moving files between drives

Posted on 2007-11-14
5
369 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Many businesses neglect disaster recovery and treat it as an after-thought. I can tell you first hand that data will be lost, hard drives die, servers will be hacked, and careless (or malicious) employees can ruin your data.
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 …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

724 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