批处理文件,用于查找文件并将其复制到当前目录以外的目标

时间:2012-08-15 23:22:33

标签: batch-file copy cmd move

我完成了一个Java程序,现在我正在创建一个批处理文件来设置它。我对批处理文件和CMD命令一无所知,这就是我问这个问题的原因:)。

这就是我已经拥有的:

@echo off
C:
md \Calc
D:
cd Calculator
move D:\Calculator\Calc.jar C:\Calc\

但是这需要用户将文件夹“calculator”放入D:\,这可能不方便,有没有办法解决这个问题?

3 个答案:

答案 0 :(得分:0)

您可以使用PUSHD C:更改目录,然后POPD将返回之前的当前目录。

答案 1 :(得分:0)

搜索文件,并将其复制到指定的位置:

for /f "tokens=*" %%a in ('dir /b/s d:\calc.jar') do copy "%%a" c:\calc\

这个问题是它会将找到的每个calc.jar复制到该位置(覆盖旧位置)。

查看dir /b/s d:\calc.jar的输出,看看它会找到哪些文件

答案 2 :(得分:0)

要通过双击运行.jar文件,请在Windows中设置文件关联:

  

http://windowstipoftheday.blogspot.com/2005/10/setting-jar-file-association.html

Open the Windows Explorer, from the Tools select 'Folder Options...'
Click the File Types tab, scroll down and select JAR File type.
Press the Advanced button.
In the Edit File Type dialog box, select open in Actions box and click Edit...
Press the Browse button and navigate to the location the Java interpreter javaw.exe.
In the Application used to perform action field, needs to display something similar to C:\Program Files\Java\j2re1.4.2_04\bin\javaw.exe"
     

-jar“%1”%(注意:以'javaw'开头的部分必须与此完全相同;路径名的其他部分可能会有所不同,具体取决于哪个   你正在使用的Java版本)然后按OK按钮直到所有   对话框已关闭。