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

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

问题描述

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

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

C:UsersJohnSmithDesktopTesting
eport-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:UsersJohnSmithDesktopTesting

然后使用:

dir report*

当我导航到时它也可以正常工作:

It also works fine when I navigate to:

C:UsersJohnSmithDesktopTesting

然后运行

copy * C:UsersJohnSmithDesktopTestingDestination

我的目标是能够在我的批处理文件中运行一些简单的东西,如下所示:

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

copy C:UsersJohnSmithDesktopTesting
eport* C:UsersJohnSmithDesktopTestingDestination

每当我尝试运行上述程序时,都会收到以下错误:

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

系统找不到指定的文件.已复制 0 个文件.`

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

有人有什么建议吗?

推荐答案

使用 For/D 与通配符作为您的目录名称,然后您可以使用 Copy 与通配符也是!

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

从命令提示符:

For /D %A In ("%UserProfile%DesktopTesting
eport-*-*-*") Do @Copy "%A*.csv" "%UserProfile%DesktopTestingDestination">Nul 2>&1

来自批处理文件:

@For /D %%A In ("%UserProfile%DesktopTesting
eport-*-*-*") Do @Copy "%%A*.csv" "%UserProfile%DesktopTestingDestination">Nul 2>&1

您也可以直接在 Powershell 提示符处执行此操作:

Alternatively you could do it directly at the Powershell Prompt:

Cp "$($Env:UserProfile)DesktopTesting
eport-*-*-**.csv" "$($Env:UserProfile)DesktopTestingDestination"

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

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