日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:python怎么拷貝文件夾

1、拷貝文件夾

專注于為中小企業(yè)提供成都做網(wǎng)站、網(wǎng)站制作服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)瀾滄免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上千余家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

from shutil import copytree, ignore_patterns
copytree(source, destination, ignore=ignore_patterns('*.pyc', 'tmp*'))

注:shutil.copytree實(shí)現(xiàn)

def copytree(src, dst, symlinks=False, ignore=None):
  names = os.listdir(src)
  if ignore is not None:
    ignored_names = ignore(src, names)
  else:
    ignored_names = set()
  os.makedirs(dst)
  errors = []
  for name in names:
    if name in ignored_names:
      continue
    srcname = os.path.join(src, name)
    dstname = os.path.join(dst, name)
    try:
      if symlinks and os.path.islink(srcname):
        linkto = os.readlink(srcname)
        os.symlink(linkto, dstname)
      elif os.path.isdir(srcname):
        copytree(srcname, dstname, symlinks, ignore)
      else:
        copy2(srcname, dstname)
      # XXX What about devices, sockets etc.?
    except (IOError, os.error) as why:
      errors.append((srcname, dstname, str(why)))
    # catch the Error from the recursive copytree so that we can
    # continue with other files
    except Error as err:
      errors.extend(err.args[0])
  try:
    copystat(src, dst)
  except WindowsError:
    # can't copy file access times on Windows
    pass
  except OSError as why:
    errors.extend((src, dst, str(why)))
  if errors:
    raise Error(errors)

2、刪除文件夾

#! /usr/bash/python
# encoding:utf-8
import os
import os.path
import stat
import shutil
class DelDir:
 ''' 刪除指定根目錄下特定文件夾 '''
 def __init__(self, root, dirname):
 self.root = root
 self.dirname = dirname
 def run(self):
 for r, dirs, files in os.walk(self.root):
  if self.dirname in dirs:
  srcDir = os.path.join(r, self.dirname)
  #更改權(quán)限(win7會(huì)出現(xiàn)權(quán)限問題)
  os.chmod(srcDir, stat.S_IREAD | stat.S_IWRITE)
  result = shutil.rmtree(srcDir, False, self.__handler)
  print "%s" %(srcDir)
 def __handler(self, function, path, excinfo):
 ''' 刪除出錯(cuò)處理 '''
 #更改權(quán)限(win7會(huì)出現(xiàn)權(quán)限問題)
 os.chmod(path, stat.S_IREAD | stat.S_IWRITE)
 function(path)
 print "[Handler] ==> Path:%s \n\tHandler the Error: %s" %(path, excinfo)
if __name__ == '__main__':
 rootdir = r"E:\workspace\minioffice\mini-core\src\main\webapp" # 需要處理的文件夾
 rootdir = unicode(rootdir, "utf8")
 dirname = ".svn" # 刪除的文件夾
 c = DelDir(rootdir, dirname)
 c.run()

眾多python培訓(xùn)視頻,盡在python學(xué)習(xí)網(wǎng),歡迎在線學(xué)習(xí)!


網(wǎng)站名稱:創(chuàng)新互聯(lián)Python教程:python怎么拷貝文件夾
鏈接分享:http://www.5511xx.com/article/dpjccig.html