Windows批处理文件:输出文件名,不带扩展名 [英] Windows Batch File: Output filename without extension

查看:1122
本文介绍了Windows批处理文件:输出文件名,不带扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows批处理文件,该文件需要一个文件,通过编译器运行该文件以缩小该文件,然后将其吐回去.我的问题是,我该如何重命名文件:

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:

我希望它从script.js变为script.min.js

我正在使用以下脚本:

@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

当我使用脚本时,它会输出文件名为script.js.min.js的文件,因此我希望可以先将.js剪切掉,然后再添加.min.js.

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.

更新:

如果有一种方法可以输出文件名,那么请附加.min.js,我想我愿意.

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

推荐答案

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

〜dpn仅选择驱动器,路径,名称部分并省略扩展名(x)

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

这篇关于Windows批处理文件:输出文件名,不带扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆