用python實(shí)現(xiàn)的可以拷貝或剪切一個文件列表中的所有文件
更新時間:2009年04月30日 00:43:52 作者:
python 實(shí)現(xiàn)剪切或是拷貝一個文件列表中的所有文件
復(fù)制代碼 代碼如下:
# coding:utf-8
import os
import sys
def cut_and_paste_file(source, destination):
'''
source: file path 中文
destination: directory path
'''
def format_path(path):
if not os.path.isabs(path):
path = os.path.join(os.getcwd(), path)
return path
def mk_dir(path):
if not os.path.exists(os.path.dirname(path)):
mkdir_cmd = 'mkdir "%s"' % os.path.dirname(path)
print os.popen(mkdir_cmd).read()
destination = os.path.join(format_path(destination), source)
source = format_path(source)
mk_dir(source)
mk_dir(destination)
copy_cmd = 'copy /Y "%s" "%s"' % (source, destination)
print 'copy_cmd:%s' % copy_cmd
print os.popen(copy_cmd).read()
del_cmd = 'del "%s" /Q' % source
print 'del_cmd:%s' % del_cmd
print os.popen(del_cmd).read()
if __name__ == '__main__':
if len(sys.argv) != 2:
print 'params must be 1,the params is the file of contain the list of cutAndPastFile List'
exit(0)
file_name = sys.argv[1]
f = open(file_name, 'r')
lst_file = f.readlines()
f.close()
output_path = 'backup_del'
for filename in lst_file:
filename = filename.replace('\n', '')
if filename != '':
cut_and_paste_file(filename, output_path)
傳一個文件給該py文件即可,例如,文件名為:del_file.txt
group1_input\subgroup13\55657_XSL_Transformations_(XSLT)_Version_2.0.doc
group1_input\subgroup6\377-6700-001 REV B .doc
group3_input\subgroup42\CGP_Manual_5_0.doc
相關(guān)文章
Python操作SQLite數(shù)據(jù)庫過程解析
這篇文章主要介紹了Python操作SQLite數(shù)據(jù)庫過程解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-09-09Python3使用matplotlib繪圖時,坐標(biāo)軸刻度不從X軸、y軸兩端開始
這篇文章主要介紹了Python3使用matplotlib繪圖時,坐標(biāo)軸刻度不從X軸、y軸兩端開始問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-08-08Python基于OpenCV實(shí)現(xiàn)人臉檢測并保存
這篇文章主要介紹了Python基于OpenCV實(shí)現(xiàn)人臉檢測并保存,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-07-07ubuntu安裝jupyter并設(shè)置遠(yuǎn)程訪問的實(shí)現(xiàn)
Jupyter?Notebook是Ipython的升級版,而Ipython可以說是一個加強(qiáng)版的交互式Shell,本文主要介紹了ubuntu安裝jupyter并設(shè)置遠(yuǎn)程訪問的實(shí)現(xiàn),感興趣的可以了解一下2022-03-03Python實(shí)現(xiàn)一個自助取數(shù)查詢工具
在數(shù)據(jù)生產(chǎn)應(yīng)用部門,取數(shù)分析是一個很常見的需求,實(shí)際上業(yè)務(wù)人員需求時刻變化,最高效的方式是讓業(yè)務(wù)部門自己來取,減少不必要的重復(fù)勞動,本文介紹如何用Python實(shí)現(xiàn)一個自助取數(shù)查詢工具2021-06-06淺談Python中的異常和JSON讀寫數(shù)據(jù)的實(shí)現(xiàn)
今天小編就為大家分享一篇淺談Python中的異常和JSON讀寫數(shù)據(jù)的實(shí)現(xiàn),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02