Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
This topic seems beaten into the ground, however, any help would be appreciated.
I'm trying to piece together a script that'll rename a season of a show.
I've been trying to learn myself. But, am still confused on several areas. For my learning experience if I am wrong could you please clarify?
:: renamer.bat
@echo off:main
for %%f in (deadwood*.avi) do call :renamer %%f
goto :eof:renamer
set old=%1
ren %1 %old:~3,9%
:: endIf the variable %%f is true(if there is a file named deadwood*.avi). Call's 'renamer'.
What is the second %%f stand for? Does this check if the variable is still true? If true repeat, if false go to end of file.I don't understand the 'set old=%1' line. I think it means set variable old to the first character of the file name. My question is this the full file name? What part of the file name is sent to 'renamer'?
'ren' is the rename command. However, '%1 %old' I'm not sure what this all means - first character of old?
The last part '~3,9%': remove the following 3 chars and keep 9.The an example file name would be 'deadwood.s02e01.ws.dvdrip.xvid-bia.avi' to be renamed to 'Deadwood S02E01.avi'
Thanks for any help, pointers, advice I receive. Regards
i suggest you use "if exist" instead..
@echo off
cls
:sets
set /A Episode=0
:begin
set /A Episode=%Episode%+1
if exist "deadwood*Ep%Episode%*.avi" ren "deadwood*Ep%Episode%*.avi" "Deadwood Episode %Episode%.avi">>Log.log & goto begin
echo all done
pause
exit(btw in case u didnt notice, i added a "log" instead of showing it on the CMD each rename)
Report Offensive Follow Up For Removal
vbscript
Set objFS = CreateObject("Scripting.FileSystemObject")
strPath = "c:\test"
Set objFolder = objFS.GetFolder(strPath)
For Each strFiles In objFolder.Files
If InStr(strFiles.Name, "deadwood") > 0 And objFS.GetExtensionName(strFiles) = "avi" Then
strName = strFiles.Name
ArrSplit = Split(strName,".")
strExt = ArrSplit(UBound(Arrsplit))
strFirstLetterUpper = UCase(Mid(ArrSplit(0) ,1,1))
strTheRest = Mid(ArrSplit(0) ,2)
strNewName = strFirstLetterUpper&strTheRest&" "&ArrSplit(1)&"."&strExt
strFiles.Name = strNewName 'rename
End If
Next
save the above as script.vbs and on command line
c:\test> cscript /nologo script.vbs
Report Offensive Follow Up For Removal
Excellent. I tried the vbscript and it worked correctly. I also added two extra lines:
strSeason = UCase(Mid(ArrSplit(1) ,1,6))
And again,
strNewName = strFirstLetterUpper&strTheRest&" "&strSeason&"."&strExt
Output: Deadwood SxxExx.avi
Initially I couldn't get the batch code to work. However, for the sake of learning I'll try to use 'if exist' statement.
Many thanks Hans and Ghostdog.
Report Offensive Follow Up For Removal
![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |