简体   繁体   English

使用目录上的通配符从文件夹复制内容

[英]Copy Contents From Folder Using Wildcard On The Directory

I have a directory which contains CSV files needing to be moved to another directory: 我有一个目录,其中包含需要移动到另一个目录的CSV文件:

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

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. 我想创建一个批处理文件以在report*上使用通配符复制此数据,但是我遇到了一些问题。

The wildcard appears to work without any issues when I first navigate to: 当我第一次导航到以下位置时,通配符似乎可以正常工作:

C:\Users\JohnSmith\Desktop\Testing\

then use: 然后使用:

dir report*

It also works fine when I navigate to: 当我导航至时,它也可以正常工作

C:\Users\JohnSmith\Desktop\Testing\

then run 然后跑

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: 每当我尝试运行以上命令时,都会出现以下错误:

The system cannot find the file specified. 该系统找不到指定的文件。 0 file(s) copied.` 已复制0个文件。

Does anyone have any suggestions? 有没有人有什么建议?

Use For /D with a wildcards for your directory name, then you can use Copy with a wildcard too! For /D与通配符一起用作目录名,然后也可以Copy通配符与Copy一起使用!

From the Command Prompt: 从命令提示符:

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

From a batch file: 从批处理文件:

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

Alternatively you could do it directly at the Powershell Prompt: 或者,您可以直接在Powershell提示符下执行此操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 批处理-使用通配符将文件夹复制到许多文件夹 - Batch - copy folder to many folders using wildcard 从通配符批处理文件确定的文件夹名称中复制文件 - Copy files from a folder name determined by wildcard batch file 使用通配符递归复制文件夹中的文件(文件夹路径中包含通配符) - Copy the files from folders recursively with wildcard characters (folder path has wildcard characters) 使用通配符进行复制 - Using a wildcard to copy 使用sas将文件从一个目录从一个文件夹复制到另一个文件夹 - copy file from one directory from one folder to another using sas 复制目录及其内容,而不使用xcopy或robocopy - copy directory and its contents without using xcopy or robocopy 使用源文件夹作为名称将文件从源目录树复制到新位置 - Copy file from source directory tree to new location using source folder as name 将子文件夹的内容复制到另一个文件夹 - Copy contents of subfolder to another folder 如何使用C#将文件夹/目录复制到剪贴板 - How to copy a folder/directory to clipboard using c# .bat文件以获取“服务目录路径”文件夹,并将文件从该文件夹复制到同一目录的子文件夹 - .bat file to get Service Directory Path folder and copy the files from that folder to subfolder of the same directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM