Python's approach to using Xcopy under Linux

Source: Internet
Author: User
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.

  • 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.