Rename all files in folder to uppercase with batch

拜拜、爱过 提交于 2019-12-07 05:14:57

问题


Is there a way to rename all files in a specific folder to uppercase with batch file?
I found this code. But it renames files to lowercase. How to modify it to rename to uppercase instead?

for /f "Tokens=*" %f in ('dir /l/b/a-d') do (rename "%f" "%f")

回答1:


@echo off
setlocal enableDelayedExpansion

pushd c:\some_dir

for %%f in (*) do (
   set "filename=%%~f"

   for %%A in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
      set "filename=!filename:%%A=%%A!"
   )
    ren "%%f" "!filename!" >nul 2>&1
)
endlocal



回答2:


This will put the extension to upper case as well.... Which was a problem for me... So this how I "kept" extension as lower case...

@echo off
setlocal enableDelayedExpansion

pushd "\...\PATH_TO_FOLDER\"

for %%f in (*) do (
   set "filename=%%~f"

   for %%A in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
      set "filename=!filename:%%A=%%A!"
   )
    ren "%%f" "!filename!" >nul 2>&1
)

for /r "\...\PATH_TO_FOLDER\" %%G in (*.PDF) do ren "%%~G" *.pdf

endlocal

replace \...\PATH_TO_FOLDER\ with your path and .PDF/.pdf with your file extention as needed.



来源:https://stackoverflow.com/questions/25199066/rename-all-files-in-folder-to-uppercase-with-batch

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