复制文件与路径中的通配符 [英] Copying Files with Wildcards in the Path

查看:176
本文介绍了复制文件与路径中的通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设存在的目录结构C:\\用户\\ myuser的\\桌面\\鲍勃\\马利

Assume there exists the directory structure C:\users\myuser\Desktop\bob\marley.

在Windows中,从起始目录C:\\用户\\ myuser的\\桌面,我可以做CD博* \\ *三月和CD到该目录鲍勃\\马利。但是,我不能做一个副本博* \\ *月C:\\

In windows, from the starting directory C:\users\myuser\Desktop I can do "cd bo*\mar*" and cd in to the directory bob\marley. However, I can't do a "copy bo*\mar* C:\"

我需要使用复制,XCOPY,或一些标准的窗户,到比赛的目录复制到目标路径通配符命令。我不知道这是否是复制和XCOPY的限制,或者如果我有错的语法。我也试过的xcopy / E / I博* \\ **月C:\\ somedirectory。

I need to use the copy, xcopy, or some standard windows command with wildcards in the path to copy the match directories to the destination. I am not sure if this is a limitation of copy and xcopy or if I have the syntax wrong. I've also tried "xcopy /E /I bo*\mar** C:\somedirectory".

推荐答案

没有 - 你不能做到这一点与COPY或XCOPY。有一个与你所问的一个根本缺陷。

No - you cannot do that with COPY or XCOPY. There is a fundamental flaw with what you are asking.

如果你也有一个名为波士顿\\马拉松目录是什么?你想哪个目录中复制?

What if you also have a directory named "boston\marathon"? Which directory do you want to copy from?

您可能会回答 - 我要两个。但现在你有一个讨厌的潜在问题。如果这两个源目录中包含一个名为test.txt的文件。你只能在你的目的地名为test.txt的一​​个文件。你养哪一个?没有正确的答案,这是一个很好的理由命令旨在不允许你正在尝试做的事情。

You might answer - "I want both". But now you have a nasty potential problem. What if both source directories contain a file named "test.txt". You can only have one file named "test.txt" in your destination. Which one do you keep? There is no correct answer, and that is a good reason why the command is designed to disallow what you are attempting to do.

附录

如果你愿意假定只有一个文件夹的模式匹配,那么你已经知道所有的步骤与以下实现你的目标。

If you are willing to assume that only one folder matches the pattern, then you already know all the steps to accomplish your goal with the following.

@echo off
cd bo*\ma*
xcopy * c:\somedirectory

如果您想返回到起始位置,然后使用PUSH​​D / POPD代替CD

If you want to return to where you started, then use PUSHD/POPD instead of CD

@echo off
pushd bo*\ma*
xcopy * c:\somedirectory
popd

但你应该非常小心。波士顿\\马拉松可能存在,并且既不PUSHD也不光盘会给任何迹象表明存在一个潜在的问题。

BUT, you should be very careful. Boston\marathon could exist, and neither PUSHD nor CD will give any indication that there is a potential problem.

这篇关于复制文件与路径中的通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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