Reputation: 77
I have multiple files like this: "Name.Of.File.M01F03.csv" But sometimes users put the file like "Name.of.the.file.m01f03.csv"
How can i search in folders and rename(capitalize) first letter after the "." excepting extension from command line? i use windows 2003 server.
Thank you.
Upvotes: 1
Views: 327
Reputation: 9545
Another way.
I just did it as a personal test to see if that can be done without showing the all alphabet.
It will take more time to do the job as the others solutions.
@echo off
pushd c:\csv_dir
setlocal enableDelayedExpansion
for %%a in (*.csv) do (set $file="%%~na"
for /l %%f in (65,1,90) do (call:replace %%f)
REN "%%~nxa" "!$file!%%~xa")
endlocal
popd
exit /b
:replace
set $valmaj=%1
cmd /c exit %$valMaj%
set $valmaj=%=exitcodeAscii%
set $file=!$file:.%$valmaj%=.%$valmaj%!
Upvotes: 0
Reputation: 67216
@echo off
setlocal EnableDelayedExpansion
cd c:\csv_dir
for %%a in (*.csv) do (
set "oldName=%%~Na"
set "newName="
for %%c in ("!oldName:.=" "!") do (
set "part=%%~c"
set "char=!part:~0,1!"
for %%d 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 "char=!char:%%d=%%d!"
set "newName=!newName!!char!!part:~1!."
)
ECHO ren "%%a" "_"
ECHO ren "%%~DPa_" "!newName:~0,-1!%%~Xa"
)
Run this Batch file as test first; if the displayed ren
commands are correct, remove the ECHO
parts.
EDIT: Second method added
Previous Batch file also capitalize the first letter. If the first letter is right, then the method may be simpler:
@echo off
setlocal EnableDelayedExpansion
cd c:\csv_dir
for %%a in (*.csv) do (
set "name=%%~Na"
for %%d 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 "name=!name:.%%d=.%%d!"
ECHO ren "%%a" "_"
ECHO ren "%%~DPa_" "!name!%%~Xa"
)
Upvotes: 1
Reputation: 57252
@echo off
pushd c:\csv_dir
setlocal enableDelayedExpansion
for %%f in (*.csv) do (
set "filename=%%~nf"
SET filename=!filename:.a=.A!
SET filename=!filename:.b=.B!
SET filename=!filename:.c=.C!
SET filename=!filename:.d=.D!
SET filename=!filename:.e=.E!
SET filename=!filename:.f=.F!
SET filename=!filename:.g=.G!
SET filename=!filename:.h=.H!
SET filename=!filename:.i=.I!
SET filename=!filename:.j=.J!
SET filename=!filename:.k=.K!
SET filename=!filename:.l=.L!
SET filename=!filename:.m=.M!
SET filename=!filename:.n=.N!
SET filename=!filename:.o=.O!
SET filename=!filename:.p=.P!
SET filename=!filename:.q=.Q!
SET filename=!filename:.r=.R!
SET filename=!filename:.s=.S!
SET filename=!filename:.t=.T!
SET filename=!filename:.u=.U!
SET filename=!filename:.v=.V!
SET filename=!filename:.w=.W!
SET filename=!filename:.x=.X!
SET filename=!filename:.y=.Y!
SET filename=!filename:.z=.Z!
REN "%%~nxf" "!filename!%%~xf"
)
popd
endlocal
Upvotes: 1