一些在Windows中的复制命令从当前位置复制到指定位置 [英] Some Copy command in windows to copy from current location to specified location

查看:261
本文介绍了一些在Windows中的复制命令从当前位置复制到指定位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我开始这样:

copy | dir /s /b | find "myFile" C:\Destination

但问题是目标不在此命令。它只能看到命令的第一部分,取消C:\ Destination。

but the problem is that the destination is not visible in this command. It only sees the first part of the command up untip C:\Destination.

是否有一种方法可以搜索文件并复制?

Is there a way I can search for a file and copy it?

我也尝试过这样:

SET source = dir /s /b | find "myFile"
SET destination = %CD%
copy %file% %destination%


$ b b

但它不工作。

but it doesn't work.

在某些时候甚至试图设置一个指向curent目录的变量(%CD%)不起作用。

At some point even trying to set a variable that points to the curent directory ( %CD% ) doesn't work.

提前感谢!

PS:我正在寻找一个可以不安装任何东西的解决方案新的计算机上,这就是为什么我在考虑批处理文件。

PS: I'm looking for a solution that would work without installing anything new on the computer, that's why I'm thinking of batch files.

我想我可以用VBscript做这个,但我不知道。

I think I could do this with VBscript but I'm not sure. If anyone thinks it's a better option please post that answer too.

推荐答案

经过几个小时的工作后,我成功地找到了正确的命令组合,以使这种情况发生。这里是给大家的,我希望它有帮助:

After a few hours of work I have managed to find the right combination of commands in order to make this happen. Here it is for you all and I hope it helps:

SET destination=%CD%
E:
for /f "delims=" %%a in ('dir /b /s ^| find "searchedFile"') do (
cd ..
xcopy "%%a" "%destination%" /D:10-10-2011)
pause

命令,因为directory命令返回了整个路径,包括该文件和当试图复制它..它认为该文件在包含其名称的路径。

I used the change directory command because the "directory" command returned the entire path, including the file and when trying to copy it.. it thought that the file was in the path that included its name.

例如,如果我在E:\Folder\New Folder\myFile.jpg中搜索myFile.jpg,它认为文件的位置是E:\Folder\New Folder \myFile.jpg\myFile.jpg,显然这不起作用。

For example, if i searched for "myFile.jpg" in "E:\Folder\New Folder\myFile.jpg" it thought that the location of the file was "E:\Folder\New Folder\myFile.jpg\myFile.jpg" and obviously this doesn't work.

这篇关于一些在Windows中的复制命令从当前位置复制到指定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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