如何将文件名附加到批处理文件中的当前目录?

时间:2023-01-18 02:23:57

I want to search a file in the current directory from which the batch is running, append the filename to the directory and include that entire directory as part of command that.

我想在当前运行批处理的目录中搜索文件,将文件名附加到目录并将整个目录包含在命令的一部分中。

So.....

Directory:
C:\tempfiles\batch

Files in C:\tempfiles\batch tmp1.txt tmp2.txt tmp3.txt anyname.exe

C:\ tempfiles \ batch中的文件tmp1.txt tmp2.txt tmp3.txt anyname.exe

I want the batch file, run from the directory, to find any .exe file and append it to the directory name, and use that new string as part of a command to copy the .exe file over to another directory. The command will eventually read like this (the FILETRANSFERSW.exe is the file transfer software that is also in the directory):

我希望从目录运行的批处理文件找到任何.exe文件并将其附加到目录名称,并使用该新字符串作为命令的一部分将.exe文件复制到另一个目录。该命令最终会像这样读取(FILETRANSFERSW.exe是文件传输软件,也在目录中):

C:\tempfiled\batch> FILETRANSFERSW.exe "%CD%\tmp4.exe" X:\dest

C:\ tempfiled \ batch> FILETRANSFERSW.exe“%CD%\ tmp4.exe”X:\ dest

The .exe file name will be changing so i need to dynamically add the new filename into the above command everytime i run the batch file. Any ideas??

.exe文件名将会更改,因此每次运行批处理文件时,我都需要在上面的命令中动态添加新文件名。有任何想法吗??

1 个解决方案

#1


If I read your problem correctly, is it sufficient to use the "for" keyword?

如果我正确地阅读了您的问题,使用“for”关键字就足够了吗?

for %a in (*.exe) do FILETRANSFERSW.exe %a X:\dest

for(* .exe)中的%a执行FILETRANSFERSW.exe%X:\ dest

You can test the output with something innocuous like:

您可以使用无关紧要的方式测试输出:

for %a in (*.exe) do echo [[%a]]

对于(* .exe)中的%a,回显[[%a]]

%a ends up iterating over *.exe in the current directory, returning the full file name for each one.

%a最终在当前目录中迭代* .exe,返回每个目录的完整文件名。

#1


If I read your problem correctly, is it sufficient to use the "for" keyword?

如果我正确地阅读了您的问题,使用“for”关键字就足够了吗?

for %a in (*.exe) do FILETRANSFERSW.exe %a X:\dest

for(* .exe)中的%a执行FILETRANSFERSW.exe%X:\ dest

You can test the output with something innocuous like:

您可以使用无关紧要的方式测试输出:

for %a in (*.exe) do echo [[%a]]

对于(* .exe)中的%a,回显[[%a]]

%a ends up iterating over *.exe in the current directory, returning the full file name for each one.

%a最终在当前目录中迭代* .exe,返回每个目录的完整文件名。