我在C:/Print中有一个包含数千个目录的文件夹。它们是用数字命名的。每个目录包含的子目录可能有不同的名称。
我想输入一个数字,然后程序必须进入与输入类似的目录,检查所有子目录中与此输入类似但扩展名为.tif的文件,然后将其复制到另一个目录。
示例:
输入"63783“
C:/Print/63783/FCB/63783.tif ->将其复制到D:/HotFolder
我能得到一些帮助吗?
发布于 2020-10-26 15:06:57
我很想帮你,但我想我们需要更多的信息,有没有不一致的帐户或服务器,我可以联系你?试试这段代码,看看它是否能工作:
import os, shutil
number = int(input("Etner number: "))
path = "C:\\Print\\" + str(number)
os.chdir(path)
destination = "D:\\HotFolder"
path_list = os.listdir()
for sub_dir in path_list:
sub_path = path+ "\\" +sub_dir
os.chdir(sub_path)
files = os.listdir()
if str(number) + ".tif" in files:
source = sub_path + "\\" + str(number) + ".tif"
shutil.move(source, destination)发布于 2020-10-26 15:24:36
def f_name(some_input):
import os, shutil
src_path = "src_dir_path"
src_path = os.path.join(src_path, some_input) # dir path to look for
dst_path = "dst_dir_path"
if not os.path.isdir(src_path): # no directory named <some_input>
return
if not os.path.isdir(dst_path): # destination folder check
os.mkdir(dst_path)
copy_targets = [(root, filename) for root, _, filenames in os.walk(src_path) for filename in filenames if filename.endswith(".tif")]
for root, filename in copy_targets:
origin = os.path.join(root, filename)
dest = os.path.join(dst_path, filename)
shutil.copyfile(origin, dest) # copy filehttps://stackoverflow.com/questions/64532497
复制相似问题