2017-03-06 81 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

相关问题