python 批量複製檔案

來源:互聯網
上載者:User
資料庫裡匯出了一個excel,裡麵包含了一些圖片檔案的檔案名稱,需把對應檔案要從伺服器上下載,程式未提供圖片大量匯出功能,只是臨時資料統計,需要手動把對應excel裡的檔案匯出。

1、把excel裡檔案名稱那一列複製,粘進一個空白的文字檔,命名為filelist.txt,上傳到伺服器。

2、在伺服器上使用指令碼匯出,python指令碼:

#! python#coding:utf-8##!/usr/bin/python# Filename : fileCp.pyimport sysimport os  import shutil fileList='filelist.txt'targetDir='files'filedir = open(fileList)line = filedir.readline()log = open('running.log','w')while line:line = line.strip('\n');basename =  os.path.basename(line)exists = os.path.exists(line)if exists :print 'copy '+line+' to '+os.getcwd()+'/'+targetDir+'/'+basenamelog.write('copy '+line+' to '+os.getcwd()+'/'+targetDir+'/'+basename+'\r\n')shutil.copy(line,targetDir+'/'+basename)else:print line+' not exists'log.write(line+' not exists'+'\r\n')line = filedir.readline()log.close()
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.