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
Solved

File Copying..

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

The really strange introduction Once upon a time there were individuals who intentionally put the grass seeds to the soil with anticipation of solving their nutrition problems. Or they maybe only played with seeds and noticed what happened... Som…
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…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
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…

837 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