2015-10-23 35 views
0

打開路徑我想實現在CMD下:搜索一個文件,並在CMD

  1. 將搜索特定文件名 - 這我知道該怎麼做,與dir /s filename
  2. 一旦發現它會使我走上這條道路。 例如:我現在在C:\上,如果在C:\test中找到該文件,那麼它將在命令提示符下打開C:\test

另外,我想只是將找到的文件複製到我將指定的路徑。我只是不知道該怎麼做,因爲我不知道文件的存儲路徑(每次都不一樣)。

在此先感謝!

+0

我設法讓替代選項工作。通過運行:'for/R%G IN(「filename.db」)DO xcopy「%G」「C:\ downloads \ Test」'。問題是當我把它放在一個批處理文件中,然後我得到一個語法錯誤,它運行'for/R G'「C:\ downloads \ Test」'而不是 – Vladi

+0

我知道了!我必須將它更改爲%% – Vladi

回答

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" 

這是否有幫助?

相關問題