Remove extension from filename

放肆的年华 提交于 2019-12-25 05:35:09

问题


In folder1 I have a list of files:

file1.exe
ahahdf.exe
ahdfkqkq.exe

I want to run a script and have it create the following files in folder2:

file1.zip
ahahdf.zip
ahdfkqkq.zip

My attempt:

for %%f in (*.*) do "c:\program files\7-zip\7z.exe" a %%f.zip %%f

This creates file1.exe.zip, ... but I need file1.zip, ... (without the .exe extension).

How can I do this?


回答1:


Should be

for %%f in (*.*) do "c:\program files\7-zip\7z.exe" a %%~nf.zip %%f

Note %%~nf - ~n tells command interpreter to pick the filename part without extension.

Also I would enclose parameters into double-quotes ("param") to ensure that filenames that contain spaces are properly handled.



来源:https://stackoverflow.com/questions/13893460/remove-extension-from-filename

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