搜索文件并在CMD中打开路径

时间:2015-10-23 02:43:16

标签: search cmd

我想在CMD中实现以下目标:

  1. 将使用dir /s filename
  2. 搜索特定文件名 - 我知道该怎么做
  3. 一旦发现,它将带我走上那条道路。 示例:我现在在C:\,如果在C:\test中找到该文件,则会在命令提示符下打开C:\test
  4. 或者,我想将找到的文件复制到我将指定的路径。我只是不知道该怎么做,因为我不知道文件存储的路径(每次都不同)。

    提前致谢!

1 个答案:

答案 0 :(得分:0)

我的问题与您的问题相混淆,但我会尝试引导您完成我编写的批处理代码,以帮助您解决此问题。

dir /b /s "test.txt" > "%userprofile%/Desktop/result.txt"

::find the file path to the file you want to find and insert it in a .txt file
::you made called result.txt (also %userprofile% is a variable that brings you to
::your user directory ex C:/users/admin)

for /F "tokens=*" %%A in (%userprofile%/desktop/result.txt) do (
    set var1=%%A
)  

::set the variable var1 equal to the first (well... only) line in the file.
::I could explain what that for loop means in detail but just remember that %%A
::is a variable set from what was found when looping through the result.txt.
xcopy /s "%var1%" "C:/wherever/you/want/it/to/go"

这有帮助??