python获取指定⽂件夹下的⽂件路径import os
import re
def print_all_file_path(init_file_path, keyword):
for cur_dir, sub_dir, included_file in os.walk(init_file_path):
if included_file:
for file in included_file:
if re.search(keyword, file):
print(cur_dir + "\\" + file)
def main():
print_all_file_path("E:\pythonProcess\DataAnalysis", ".py")
python怎么读文件夹下的文件夹
if__name__ == '__main__':
main()
python将⼀个⽂件夹下的⽂件复制到另⼀个⽂件
import shutil
import os
def remove_file(old_path, new_path):
print(old_path)
print(new_path)
filelist = os.listdir(old_path) #列出该⽬录下的所有⽂件,listdir返回的⽂件列表是不包含路径的。
print(filelist)
for file in filelist:
src = os.path.join(old_path, file)
dst = os.path.join(new_path, file)
print('src:', src)
print('dst:', dst)
if__name__ == '__main__':
remove_file(r"/data/temp1", r"/data/temp2")

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。