473,394 Members | 1,285 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

shutil & verbose feedback

46
hey guys

any ideas on how to get shutil.copytree to give feedback with what it is copying? (verbose style?)

i can't seem to google up anything on it

cheers if you can help!

Adam
Jun 16 '07 #1
4 4049
bartonc
6,596 Expert 4TB
hey guys

any ideas on how to get shutil.copytree to give feedback with what it is copying? (verbose style?)

i can't seem to google up anything on it

cheers if you can help!

Adam
Hey Adam. I have an idea... Take the docs at their word and "XXX Consider this example code rather than the ultimate tool". Start with source and start adding to it to make your own verbose copytree():
Expand|Select|Wrap|Line Numbers
  1.  
  2. def copytree(src, dst, symlinks=False):
  3.     """Recursively copy a directory tree using copy2().
  4.  
  5.     The destination directory must not already exist.
  6.     If exception(s) occur, an Error is raised with a list of reasons.
  7.  
  8.     If the optional symlinks flag is true, symbolic links in the
  9.     source tree result in symbolic links in the destination tree; if
  10.     it is false, the contents of the files pointed to by symbolic
  11.     links are copied.
  12.  
  13.     XXX Consider this example code rather than the ultimate tool.
  14.  
  15.     """
  16.     names = os.listdir(src)
  17.     os.mkdir(dst)
  18.     errors = []
  19.     for name in names:
  20.         srcname = os.path.join(src, name)
  21.         dstname = os.path.join(dst, name)
  22.         try:
  23.             if symlinks and os.path.islink(srcname):
  24.                 linkto = os.readlink(srcname)
  25.                 os.symlink(linkto, dstname)
  26.             elif os.path.isdir(srcname):
  27.                 copytree(srcname, dstname, symlinks)
  28.             else:
  29.                 copy2(srcname, dstname)
  30.             # XXX What about devices, sockets etc.?
  31.         except (IOError, os.error), why:
  32.             errors.append((srcname, dstname, why))
  33.         # catch the Error from the recursive copytree so that we can
  34.         # continue with other files
  35.         except Error, err:
  36.             errors.extend(err.args[0])
  37.     if errors:
  38.         raise Error, errors
Jun 16 '07 #2
ateale
46
cheers bartonc! didn't know you could do that!
Jun 16 '07 #3
bartonc
6,596 Expert 4TB
cheers bartonc! didn't know you could do that!
In fact it's encouraged! With modules that provide object interfaces, we subclass.
With modules that have functionality that needs adding to, do it. Then, when you post here, it goes out into the public and python grows! That's really the way that a lot of the current library was built (albeit, in a slightly more controlled environment).

And you can call me Barton.

Cheers, Adam.
Jun 16 '07 #4
ateale
46
Cheers Barton!

Ahhh so much to learn!

I am really enjoying learning the language so far. It seems to be starting to make some sense

Cheers for your help!

Adam
Jun 16 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: bmgz | last post by:
I am have made a simple script that moves all desktop clutter (ie files that are not *.lnk) to a specified folder eg. c:\myhome\mydocs\desktopdebris\2003-12-16 ...
6
by: Daniel Bickett | last post by:
Hello, I'm writing an application in my pastime that moves files around to achieve various ends -- the specifics aren't particularly important. The shutil module was chosen as the means simply...
1
by: Todd7 | last post by:
I am writing a python program to load a pdf file into an IEHtmlWindow which displays it through adobe acrobat reader 7. Depending on the buttons the user clicks, the program moves it to another...
6
by: Antoine De Groote | last post by:
Google tells quite some things about it, but none of them are satisfactory. I'm on Windows, and shutil operations (e.g. move, copy) throw Permission denied all the time, for the source files. It...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
8
by: David Nicolson | last post by:
Hi, I wasn't exactly sure where to send this, I don't know if it is a bug in Python or not. This is rare, but it has occurred a few times and seems to be reproducible for those who experience...
0
by: SpaceMarine | last post by:
hello, im having a discussion w/ one of my associates, and we're are trying to get a consensus on a possible performance scenario. we're working a/ 3-rd party component that produces PDFs using...
4
by: Roopesh | last post by:
Hi, I have a multithreaded application. There are two threads, T1 and T2. Suppose that there are two folders A, B. Thread T1 fetches data from network and creates files in folder A and after...
4
by: klia | last post by:
hello folks i am trying to tweak the current codes so that later when i call it from the terminal i can provide sourcefile and the destination file rather being fixed in the code. because now i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.