使用目录上的通配符从文件夹复制内容 [英] Copy Contents From Folder Using Wildcard On The Directory

查看:134
本文介绍了使用目录上的通配符从文件夹复制内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个目录,其中包含需要移动到另一个目录的CSV文件:

I have a directory which contains CSV files needing to be moved to another directory:

C:\Users\JohnSmith\Desktop\Testing\report-20180819040000-20180826040000-4

我们收到一个新文件每周一次,目录名称中的日期将被更新。我想创建一个批处理文件,以在 report * 上使用通配符复制此数据,但是遇到了一些问题。

We receive a new file weekly where the dates in the directory name will be updated. I want to create a batch file to copy this data using a wildcard on report* but I am running into some issues.

当我第一次导航至以下位置时,通配符似乎没有任何问题

The wildcard appears to work without any issues when I first navigate to:

C:\Users\JohnSmith\Desktop\Testing\

然后使用:

dir report*

我导航到:

C:\Users\JohnSmith\Desktop\Testing\

然后运行

copy * C:\Users\JohnSmith\Desktop\Testing\Destination

我的目标是以便能够在我的批处理文件中运行如下所示的简单操作:

My goal is to be able to run something simple in my batch file like the below:

copy C:\Users\JohnSmith\Desktop\Testing\report* C:\Users\JohnSmith\Desktop\Testing\Destination

每当我尝试运行上述命令时,都会出现以下错误:

Whenever I try running the above, I receive the following error:

系统找不到指定的文件。
0个文件已被复制。

The system cannot find the file specified. 0 file(s) copied.`

有人有任何建议吗?

推荐答案

用于/ D 用于通配符作为目录名,然后可以使用也使用通配符复制

Use For /D with a wildcards for your directory name, then you can use Copy with a wildcard too!

从命令提示符处:

For /D %A In ("%UserProfile%\Desktop\Testing\report-*-*-*") Do @Copy "%A\*.csv" "%UserProfile%\Desktop\Testing\Destination">Nul 2>&1

从批处理文件中:

@For /D %%A In ("%UserProfile%\Desktop\Testing\report-*-*-*") Do @Copy "%%A\*.csv" "%UserProfile%\Desktop\Testing\Destination">Nul 2>&1

或者,您也可以直接在Powershell提示符下执行此操作:

Alternatively you could do it directly at the Powershell Prompt:

Cp "$($Env:UserProfile)\Desktop\Testing\report-*-*-*\*.csv" "$($Env:UserProfile)\Desktop\Testing\Destination"

这篇关于使用目录上的通配符从文件夹复制内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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