Windows Batch File: Output filename without extension

*爱你&永不变心* 提交于 2019-12-11 19:34:54

问题


I have a windows batch file which takes a file, runs it through a compiler to minify the file, then spits it back out. My question is, how can I rename the file like so:

I want it to go from script.js to script.min.js

I am using the below script:

@ECHO OFF
ECHO.
FOR %%c in (C:\source\*.*) DO java -jar ./Compiler/compiler.jar %%c --js_output_file %%c.min.js
ECHO.
PAUSE
CLS
EXIT

When I use the script, it outputs the file with a filename of script.js.min.js so I was hoping that I could just cut out the .js first, and then append the .min.js afterward.

UPDATE:

If there is a way to output the name of the file then append .min.js I think I would prefer that.


回答1:


FOR %%c in (C:\source\*.*) DO java -jar ./Compiler/compiler.jar %%c --js_output_file %%~dpnc.min.js

The ~dpn selects just the drive,path,name portions and omits the extension (x)



来源:https://stackoverflow.com/questions/21689704/windows-batch-file-output-filename-without-extension

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