Solved

File Copying..

Posted on 2006-10-28
3
176 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
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 28

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
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 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…

744 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

13 Experts available now in Live!

Get 1:1 Help Now