Batch renaming files after certain character

限于喜欢 提交于 2021-02-11 04:52:13

问题


I have a bunch of video files with names like so:

6592110904-Ivory-2.mp4
6592280588-Cornflower.mp4
6592321696-Ballet Pink.mp4

I want to rename them to get rid of everything after the first hyphen so they end up like:

6592110904.mp4
6592280588.mp4
6592321696.mp4

How do I go about doing this?


回答1:


Please put the code below in a bat file, place it in directory with mp4 files. Before running real renaming, please remove "echo" before "move". please be carefull with renaming bacause (theoretically) it is possible to have same name for different files.You'll be prompted to confirm if you want to override the old one.

Code splits each filename after dash and renames the file taking first item. Good luck.

@echo off

for /F "tokens=1,* delims=-" %%a in ('dir /A-D /B "*.mp4"') do (
    echo move "%%a-%%b" "%%a%%~xb"
)


来源:https://stackoverflow.com/questions/21462108/batch-renaming-files-after-certain-character

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