How to Append to existing file name within a batch command in a for loop

前提是你 提交于 2019-12-11 09:04:48

问题


I am trying to create a batch file for a project, which reads through the files in a directory and runs a command for each file that manipulates a file in some way (from another program). While running the program, it saves each manipulated file to an output folder, with the extension "_updated". How can I do this in my command using a batch file without the extension of the file becoming a part of the file name? for instance, the o/p goes from "Videoa.bin" to "Videoa.bin_updated.bin". How can I fix this? Code below!

@ECHO ON

cd [filename]
SET v=output_folder
mkdir %v%

for %%a in ([path to files]*\.bin) do [command, which takes in the following args: 
                                       output file name (the one with the _updated ext),
                                       and input folder(+more)]

PAUSE

回答1:


I suppose you are looking at something like this, the following will only echo the new modified filename..

@echo off
set "input=D:\input_folder\"
SET "output=C:\output_folder\"
mkdir %output% > nul 2>&1
for %%a in ("%input%*.bin") do echo "%%~na_update.%%~xa"

So the original filename will be %%a name of file only will be %%~na and extension only will be %%~xa

For more on this, I suggest you run the help to see detail about variable expansion.

  • for /?

As for the other command portions you have mentioned, I do not know anything about it as you have not specified any detail about it, so you would need to figure out how it will fit the above code, or edit your question and show a bit more detail about how you manually run the command for help on automating it.



来源:https://stackoverflow.com/questions/55486477/how-to-append-to-existing-file-name-within-a-batch-command-in-a-for-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!