用python實現(xiàn)的可以拷貝或剪切一個文件列表中的所有文件
更新時間:2009年04月30日 00:43:52 作者:
python 實現(xiàn)剪切或是拷貝一個文件列表中的所有文件
復制代碼 代碼如下:
# 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使用concurrent.futures模塊實現(xiàn)多進程多線程編程
Python的concurrent.futures模塊可以很方便的實現(xiàn)多進程、多線程運行,減少了多進程帶來的的同步和共享數(shù)據(jù)問題,下面就跟隨小編一起了解一下concurrent.futures模塊的具體使用吧2023-12-12
使用python調(diào)用瀏覽器并打開一個網(wǎng)址的例子
這篇文章主要介紹了使用python調(diào)用瀏覽器并打開一個網(wǎng)址的例子,使用webbrowser模塊實現(xiàn),需要的朋友可以參考下2014-06-06
python中Tkinter復選框Checkbutton是否被選中判斷
這篇文章主要介紹了python中Tkinter復選框Checkbutton是否被選中判斷方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-01-01
一文讓你徹底搞懂Python中__str__和__repr__
這篇文章主要介紹了Python中的__str__和__repr__的異同,__str__和__repr__是基本的內(nèi)置方法,文中有詳細的代碼示例,感興趣的同學可以參考閱讀下2023-05-05
Python中.py程序在CMD控制臺以指定虛擬環(huán)境運行
本文主要介紹了Python中.py程序在CMD控制臺以指定虛擬環(huán)境運行,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-07-07

