Solved

Program and method for moving files between drives

Posted on 2007-11-14
5
354 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 28

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 28

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
I previously wrote an article addressing the use of UBCD4WIN and SARDU. All are great, but I have always been an advocate of SARDU. Recently it was suggested that I go back and take a look at Easy2Boot in comparison.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now