05 從源資料夾中批量搜尋檔案複製到另乙個資料夾中

2021-10-05 01:36:38 字數 1387 閱讀 6013

**記錄,無實際意義

#!/usr/bin/python

# -*- coding: utf-8 -*-

""" 功能:在資料夾中批量搜尋檔案複製到另乙個資料夾中

"""import os

import shutil

src_dir_path =

'\\\\10.3.2.102\華泰專案二期檔案\非財務\a股'

# 源資料夾

to_dir_path =

'e:/fail/qianmj'

# 存放複製檔案的資料夾

f =open

(r'wb.txt'

,'r'

, encoding=

'utf-8'

)txt = f.readlines(

)a =

i =0

for w in txt:

w = w.replace(

'\n',''

)keys =

[x.strip(

)for x in a]

# 源資料夾中的檔案包含字元key則複製到to_dir_pat**件夾中

ifnot os.path.exists(to_dir_path)

:print

("to_dir_path not exist,so create the dir"

) os.mkdir(to_dir_path,1)

if os.path.exists(src_dir_path)

:print

("src_dir_path exitst"

)for

file

in os.listdir(src_dir_path)

:# is file

if os.path.isfile(src_dir_path+

'/'+

file):

for key in keys:

if key in

file

:print

('找到包含"'

+key+

'"字元的檔案,絕對路徑為----->'

+src_dir_path+

'/'+

file

)print

('複製到----->'

+to_dir_path+

file

) shutil.copy(src_dir_path+

'/'+

file

, to_dir_path+

'/'+

file

) i +=

1print

(i)

批量刪除資料夾中的 svn資料夾

記事本 輸入 之間的文字,注意最下面有個回車換行 windows registry editor version 5.00 hkey local machine software classes folder shell deletesvn delete svn floder hkey local ...

Matlab中從資料夾中批量讀取檔案的做法

function read data batch read file file type 檔案已完成,程式已修正 可以讀取的檔案中,若有列數不相同的,則補 nan 資料檔案中只能是數字 xls 檔案只能是英文或數字命名 批量讀資料的程式 注,只能讀取 txt類檔案,且檔案必須有字尾名 read da...

批量命名資料夾 檔案?

批量命名資料夾 檔案?01 批量重新命名資料夾 批量重新命名資料夾 如上圖所示,需要重新命名一批資料夾。你只需要新建乙個記事本,開啟,在其中輸入下面的5行 set a 00 setlocal enabledelayedexpansion for f tokens i in dir a d b do ...