command line batch remove _ from its file name

陌路散爱 提交于 2019-12-11 20:07:23

问题


I have multiple files and would like to rename its file.
For example, I have

"2014_19_24_english_test.doc"

and to change it to

"2014 19 24 english test.doc"

Here is what I have done so far:

for /f "delims=" %%f in ('dir /b *.hwp') do ren "%%~f" "%%~nf:_= %%~xf"

and this is not working. Any help would be appreciated,

Chris


回答1:


You cannot use the substring replacement syntax with for variables, so you need an interim variable to do that, using delayed expansion:

setlocal EnableDelayedExpansion
for /f "delims=" %%f in ('dir /b *.hwp') do (
    set "FNAME=%%~nf"
    ren "%%~ff" "!FNAME:_= !%%~xf"
)
endlocal



回答2:


I found it out and this is what I did :

for /f "delims=" %%i in ('dir /b "*.doc"') do set LIST=%%i & set LIST | ren "%%~fi" "%%LIST:_= %%"

Hope this helps.



来源:https://stackoverflow.com/questions/33138055/command-line-batch-remove-from-its-file-name

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