我想在CMD中实现以下目标:
dir /s filename
C:\
,如果在C:\test
中找到该文件,则会在命令提示符下打开C:\test
。或者,我想将找到的文件复制到我将指定的路径。我只是不知道该怎么做,因为我不知道文件存储的路径(每次都不同)。
提前致谢!
答案 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"
这有帮助??