Solved

File Copying..

Posted on 2006-10-28
3
186 Views
Last Modified: 2010-04-16
I am pretty new to Python. Can someone tell me/good tutorial how to make file copies in Python..
0
Comment
Question by:templeavenue
[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
3 Comments
 

Expert Comment

by:zenpro
ID: 17826403
Hi templeavenue,

you can use the following:

import shutil
shutil.copy2(source, destination)


shutil.copy will perform the copy using the current date and time, while copy2 will copy over also the date and time of the original file's last modification. You can read more about Shutil here: http://docs.python.org/lib/module-shutil.html

0
 

Author Comment

by:templeavenue
ID: 17827497
sorry... actually..what I wanted to do is read a drive (hard dirve, cd) without knowing the name/structures of the file/folders(if possible)... sorry for confusion... can i still use those functions??

Thanks,
Kelvin
0
 
LVL 29

Accepted Solution

by:
pepr earned 50 total points
ID: 17836428
The os module may be your friend. Try this to list all the directories and files from the root. Have a look at the walk() function in the stadard Python documentation. You can process the retrieved information in the way you need and possibly to combine it with the above mentioned shutil module.

import os

top = '/'
for dirpath, dirnames, filenames in os.walk(top):
    print dirpath

    for d in dirnames:
        print '  D  ' +  os.path.join(dirpath, d)

    for f in filenames:
        print '  F  ' +  os.path.join(dirpath, f)

    print



0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
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…

717 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