The examples in this article describe Python's approach to using Xcopy under Linux. Share to everyone for your reference. Specific as follows:
This Python function mimics the xcopy command written under Windows and can be used under Linux
#!/usr/bin/python#-*-coding:utf-8-*-"" "Xcopy for Linux ... Use:______________________________________________________________________________import sys, Ossys.path.insert ( 0,r "/path/to/linuxxcopy") from linuxxcopy import xcopyfilters = ["*.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__ = "/http/ Www.jensdiemer.de "__info__ =" "__version__=" 0.1 "__history__=" "V0.1-erste version" "Import OS, Shutil, Fnmatchclass X Copy:def __init__ (self, SRC, DST, filters=[]): Self.filters = Filters Self.copytree (src, DST) def copytree (self, SRC, DST): "" "Based in Shutil.copytree ()" "" names = Os.listdir (src) if not os.path.isdir (DST): os.ma Kedirs (DST) errors = [] for name in names:srcname = Os.path.join (src, name) DstName = 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) Shuti L.copystat (SRC, DST) def filtername (self, fileName): For filter in Self.filters:if fnmatch.fnmatch (FileName, fil ter): Return True return False
Hopefully this article will help you with Python programming.