[英]copy files and folders to another path using batch
I have a directory c:/go, inside go there is tons of folders, subfolders and files.我有一个目录 c:/go,在 go 里面有大量的文件夹、子文件夹和文件。
I need to find inside go, files that start with net*.inf and oem*.inf, and copy the folder, subfolders and all files where they are to another palce at c:/我需要在 go 中找到以 net*.inf 和 oem*.inf 开头的文件,并将它们所在的文件夹、子文件夹和所有文件复制到 c 的另一个位置:/
It must be something automatic using windows... like batch script, c++, python...vbs pleasee!!它必须是自动使用 windows... 像批处理脚本,c++,python...vbs 请! thanks in advance
提前致谢
The xcopy technique in @ars' answer is obviously simpler for your situation if it is appropriate for you. @ars 答案中的 xcopy 技术显然更适合您的情况,如果它适合您的话。 However, below is a Python implementation.
但是,下面是 Python 实现。 It will make sure the target directory is there and create it if it isn't:
它将确保目标目录存在,如果不存在则创建它:
#!python
import os
import re
import shutil
def parse_dir(src_top, dest_top):
re1 = re.compile("net.*\.inf")
re2 = re.compile("oem.*\.inf")
for dir_path, dir_names, file_names in os.walk(src_top):
for file_name in file_names:
if re.match(re1, file_name) or re.match(re2, file_name):
target_dir = dir_path.replace(src_top, dest_top, 1)
if not os.path.exists(target_dir):
os.mkdir(target_dir)
src_file = os.path.join(dir_path, file_name)
dest_file = os.path.join(target_dir, file_name)
shutil.copyfile(src_file, dest_file)
src_top = "\\go"
dest_top = "\\dest"
parse_dir(src_top, dest_top)
Improvements are probably possible, but this should get you started if you want to go this way.改进可能是可能的,但如果您想以这种方式 go,这应该可以帮助您入门。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.