根据文件名将一组文件复制到特定目录中 [英] Copy a set of files into specific directories based on filename

查看:189
本文介绍了根据文件名将一组文件复制到特定目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据Windows中的每个文件名将位于一个文件夹中的一系列文件复制到指定的文件夹中?

How can I copy series of files located in one folder into a specified folder based on the each file name in Windows?

例如文件:

ProviderA.pdf 复制到文件夹-> \ ProviderA \ report \

ProviderA.pdf copied to folder-> \ProviderA\report\

ProviderB.pdf 复制到文件夹-> \ ProviderB \ report \

ProviderB.pdf copied to folder-> \ProviderB\report\

ProviderC.pdf 已复制到文件夹-> \ ProviderC \ report \

ProviderC.pdf copied to folder-> \ProviderC\report\

我想遍历文件列表,并且可以从文件名(减去扩展名)中复制每个文件到文件名指定的文件夹中.

I would like to traverse the list of files and from the file name (minus the extension) be able to copy each file to the folder specified by the file name.

提前谢谢!

推荐答案

最简单的方法是循环浏览当前文件夹中的文件,如果该文件名不存在,则使用文件名(不带扩展名)创建一个文件夹,然后复制文件进入新文件夹.

Simplest way is to loop through files in current folder, create a folder using the filename (without the extension) if it doesn't already exist, then copy file into the new folder.

for %%G in (*.pdf) do (
    if not exist %%~nG md %%~nG
    copy %%G %%~nG
)

这篇关于根据文件名将一组文件复制到特定目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆