[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Program and method for moving files between drives

Posted on 2007-11-14
5
Medium Priority
?
378 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 80 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 1640 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 1640 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
Windows Server 2003 introduced persistent Volume Shadow Copies and made 2003 a must-do upgrade.  Since then, it's been a must-implement feature for all servers doing any kind of file sharing.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
This video teaches viewers how to encrypt an external drive that requires a password to read and edit the drive. All tasks are done in Disk Utility. Plug in the external drive you wish to encrypt: Make sure all previous data on the drive has been …
Suggested Courses

650 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