Python's way to use Xcopy under Linux

Source: Internet
Author: User
Tags join

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.