The examples in this article describe how Python uses xcopy under Linux. Share to everyone for your reference. Specifically as follows:
This Python function mimics the xcopy command written under Windows and can be used under Linux
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 This is the |
#!/usr/bin/python #-*-coding:utf-8-*-"" Xcopy for Linux ... Use: ______________________________________________________________________________ import sys, OS Sys.path.insert ( 0,r "/path/to/linuxxcopy") from linuxxcopy import xcopy filters = ["*.py"] xc = XCopy (OS.GETCWD (), "/tmp/test", filters) __ ____________________________________________________________________________ "" "__author__ =" Jens Diemer "__ license__ = "" "GNU general Public License v2 or above-http://www.opensource.org/licenses/gpl-license.php" "__url__ =" h Ttp://www.jensdiemer.de " __info__ =" " __version__=" 0.1 " __history__=" "V0.1-erste version" "Imp Ort OS, Shutil, Fnmatch class Xcopy:def __init__ (self, SRC, DST, filters=[]): SELf.filters = Filters Self.copytree (src, DST) def copytree (self, SRC, DST): "" "Based in Shutil.copytree ()" "" Names = OS.L Istdir (SRC) if not os.path.isdir (DST): Os.makedirs (DST) errors = [] for name in names:srcname = Os.path.join (src, name) d Stname = Os.path.join (DST, name) if Os.path.isdir (SrcName): Self.copytree (SrcName, DstName) elif Os.path.isfile (srcname ): If Self.filtername (name): print "copy:", Name, DstName shutil.copy2 (SrcName, DstName) shutil.copystat (SRC, DST) def fil Tername (self, fileName): For filter in self.filters:if fnmatch.fnmatch (filename, filter): Return True to return False |
I hope this article will help you with your Python programming.