用python實(shí)現(xiàn)的可以拷貝或剪切一個(gè)文件列表中的所有文件
更新時(shí)間:2009年04月30日 00:43:52 作者:
python 實(shí)現(xiàn)剪切或是拷貝一個(gè)文件列表中的所有文件
復(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)
傳一個(gè)文件給該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模塊實(shí)現(xiàn)多進(jìn)程多線程編程
Python的concurrent.futures模塊可以很方便的實(shí)現(xiàn)多進(jìn)程、多線程運(yùn)行,減少了多進(jìn)程帶來的的同步和共享數(shù)據(jù)問題,下面就跟隨小編一起了解一下concurrent.futures模塊的具體使用吧2023-12-12
Python 正則表達(dá)式進(jìn)階用法之字符集與字符范圍詳解
本文詳細(xì)介紹了Python正則表達(dá)式中的字符集和字符范圍,包括字符集的基本概念、特殊字符、示例和注意事項(xiàng),通過這些進(jìn)階用法,我們可以更高效地處理復(fù)雜的文本模式,感興趣的朋友跟隨小編一起看看吧2024-11-11
Python中enumerate函數(shù)及其應(yīng)用詳解
在 Python 編程中,enumerate 函數(shù)是一個(gè)非常實(shí)用的工具,它能夠?qū)⒁粋€(gè)可迭代對象組合為一個(gè)索引序列,同時(shí)列出數(shù)據(jù)和數(shù)據(jù)下標(biāo),這種功能在處理列表、元組、字符串等可迭代對象時(shí)非常有用,尤其是在需要同時(shí)獲取每個(gè)元素的索引和值的情況下,需要的朋友可以參考下2025-01-01
使用python調(diào)用瀏覽器并打開一個(gè)網(wǎng)址的例子
這篇文章主要介紹了使用python調(diào)用瀏覽器并打開一個(gè)網(wǎng)址的例子,使用webbrowser模塊實(shí)現(xiàn),需要的朋友可以參考下2014-06-06
python中Tkinter復(fù)選框Checkbutton是否被選中判斷
這篇文章主要介紹了python中Tkinter復(fù)選框Checkbutton是否被選中判斷方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01
一文讓你徹底搞懂Python中__str__和__repr__
這篇文章主要介紹了Python中的__str__和__repr__的異同,__str__和__repr__是基本的內(nèi)置方法,文中有詳細(xì)的代碼示例,感興趣的同學(xué)可以參考閱讀下2023-05-05
Python中.py程序在CMD控制臺以指定虛擬環(huán)境運(yùn)行
本文主要介紹了Python中.py程序在CMD控制臺以指定虛擬環(huán)境運(yùn)行,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07

