2017-03-06 127 views
0

我想在我的Downloads文件夾中打開每個以.jar結尾的文件。我的代碼不起作用。我做錯了什麼,如何實現我的最終目標?如何使用相同的擴展名打開多個文件

代碼:

del /s /q "C:\Users\%USERNAME%\AppData\Roaming\.minecraft\session.*" 
cls 
:choice 
cls 
set /P c=Open the file? [Y/N] 
if /I "%c%" EQU "Y" goto :start 
if /I "%c%" EQU "N" goto :choice 
goto :choice 

:start 
start "" "C:\Users\Home Computer\Downloads\????.jar" 
del /s /q "C:\Windows\Prefetch\JAVA*.pf" 
del /s /q "C:\Users\Home Computer\Recent\*.bat.lnk" 
del /s /q "C:\Users\Home Computer\Recent\????.jar.*" 
del /s /q "C:\Users\Home Computer\Recent\Downloads.lnk" 
pause 

編輯:我還要提到的是該.jar的名稱每次我重新下載時間而改變。我無法專門通過文件名來定位它。文件名總是四個字符。

看看這兩個截圖。 https://gyazo.com/579ebd940bcd74f3a3deeb05db7b337d

https://gyazo.com/ceaffd97bf1f1e81860036810b35fcd7

+0

奇怪;這應該工作。它是否啓動了任何jar文件? – SomethingDark

+0

不可以。看看這個:https://gyazo.com/579ebd940bcd74f3a3deeb05db7b337d – Quizzed

+0

這些文件顯示在'dir「C:\ Users \ Home Computer \ Downloads」'的輸出中嗎?奇怪的是 – SomethingDark

回答

0

如果該文件的名稱具有相同的字符數,每次,那麼你可以使用?爲每個字符而不是*。 說,文件名是長3個字符,那麼你可以寫命令:

start "" "C:\Users\Home Computer\Downloads\???.jar" 

也許你可以從下面的鏈接給出一些參考:

https://www.howtogeek.com/111859/how-to-batch-rename-files-in-windows-4-ways-to-rename-multiple-files/

+0

。這發生在* .jar和????. jar - https://gyazo.com/ceaffd97bf1f1e81860036810b35fcd7 – Quizzed

+0

然後也許目標文件的IP不是靜態的。 –

+0

目標文件的IP?你的意思是我從哪裏得到的?這個名字每次都是隨機的。 – Quizzed

0

嘗試

start "" "C:\Users\Home Computer\Downloads\*.jar" 

java -jar "C:\Users\Home Computer\Downloads\*.jar" 
0

您可以使用Where命令來識別下載文件的名稱。 (當然,如果你沒有一個以上的四個字符的.jar文件,它只會識別它)

@Echo Off 
Del/S/Q "%AppData%\.minecraft\session.*" 2>Nul 

:Pick 
ClS 
Choice /M "Open the file" 
If ErrorLevel 3 GoTo :EOF 
If ErrorLevel 2 GoTo Pick 
If ErrorLevel 1 GoTo Start 
GoTo :EOF 

:Start 
For /F "Delims=" %%A In ('Where "%UserProfile%\Downloads":"????.jar"' 
) Do (Set "FullName=%%~fA" & Set "Name=%%~nxA") 
Start "" "%FullName%" 
Del/Q "%SystemRoot%\Prefetch\JAVA*.pf" 2>Nul 
Del/Q "%UserProfile%\Recent\%~nx0.lnk" 2>Nul 
Del/Q "%UserProfile%\Recent\%Name%.lnk" 2>Nul 
Del "%UserProfile%\Recent\Downloads.lnk" 2>Nul 
Timeout -1 

你甚至可以縮短一點點被刪除快捷方式的一個以上來自同一個刪除行
您用於recent的位置實際上只是現代Windows版本中真實位置的鏈接,因此您可以用%AppData%\Microsoft\Windows\Recent替換%UserProfile%\Recent

相關問題