Script to rename files to parent folder, move renamed file and delete empty folder

↘锁芯ラ 提交于 2020-01-05 07:25:51

问题


Wondering if anyone here can help me out. I'm using Windows 7 and have a collection of movies and TV shows in individual folders which I'd like to be renamed to that of the folder name. For example:

../Media Files/Example Movie (2013)/EM2013.avi

to:

../Media Files/Example Movie (2013)/Example Movie (2013).avi

I'd then like the newly named file to be moved to the Media Files folder, and for the (then empty) folder to be deleted. So:

..Media Files/Example Movie (2013).avi

I've searched for a solution but only found scripts which do one or the other (How to rename a file according his folder name via batch script) - I'm after a script that can do all three things in one go as I will be adding movies and TV shows to the Media Files folder on a regular basis. Thanks in advance to anyone that can help and apologize if anything similar has been asked before.


回答1:


@ECHO OFF
SETLOCAL
SET target=.\media files
FOR /f "delims=" %%t IN (
 ' dir /b /ad "%target%" ' ) DO (
 FOR /f "delims=" %%f IN (
  ' dir /b /a-d "%target%\%%t\*.*" ' ) DO (
  ECHO MOVE "%target%\%%t\%%f" "%target%\%%t%%~xf"
  ECHO RD "%target%\%%t"
  )
)
PAUSE

Should display the required operations. Remove the ECHO keyword after verification to execute



来源:https://stackoverflow.com/questions/15376485/script-to-rename-files-to-parent-folder-move-renamed-file-and-delete-empty-fold

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