Hi!
I have a lot of *.epub-files (5000) with*.opf-file inside each epub. The names of files are not correct (a001, a002...). Inside each -*.opf is info about book in such format:
<*"aut"*>author</dc:creator>
<dc:title*>title</dc:title>
How can i create a *.bat-file, that renames all the archives in format author-title (Paulo Coelho-Achhemist)? Thanks for help.
Rename Epub files
Moderator: DosItHelp
Re: Create a bat-file
How do you open *epub to see *opf & inside *opf the info?
Re: Create a bat-file
This uses 7-Zip in the default location.
It creates renbooks.bat.txt with the rename commands - examine it in notepad to see if it is what you want.
It writes *.opf files to, and deletes them from, the current folder - if you have *.opf files there then move them.
It creates renbooks.bat.txt with the rename commands - examine it in notepad to see if it is what you want.
It writes *.opf files to, and deletes them from, the current folder - if you have *.opf files there then move them.
Code: Select all
@echo off
for /f "delims=" %%a in ('dir *.epub /b /s /a-d') do call :next "%%a"
cls
echo done
echo check renbooks.bat.txt in notepad, and rename to .bat and run if ok.
pause
goto :EOF
:next
set "auth="
set "title="
del *.opf 2>nul
"c:\Program Files\7-Zip\7z.exe" e "%~1" -r *.opf
for %%b in (*.opf) do (
for /f "tokens=3,4 delims=<>" %%c in ('type "%%b"') do (
if /i "%%d"=="/dc:creator" set "auth=%%c"
if /i "%%d"=="/dc:title" set "title=%%c"
)
)
del *.opf 2>nul
if defined auth if defined title (
>>renbooks.bat.txt echo ren "%~1" "%auth% - %title%%~x1"
) else (
>>renbooks.bat.txt echo :: "%~1" has no author - title
)
Re: Rename Epub files
Thank You!!!
And how do i use REN command to rename many files (about 2000) to get result like
z00o1.zip, z0002.zip ("serialize" file names)
Thanks again!
And how do i use REN command to rename many files (about 2000) to get result like
z00o1.zip, z0002.zip ("serialize" file names)
Thanks again!
Re: Rename Epub files
Here's a tool to help:
Code: Select all
::Renumber.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: 2004-03-10 - Idea from foxidrive in a.m.b.nt
:: 2004-03-10 - Enhanced by Matthias Tacke
:: 2004-03-11 - Rejigged again by foxidrive
@echo off
setlocal enableextensions
if [%1]==[] goto :Usage
:: the following two lines disable the persistent Offset/RenInc
set /A Offset=1
set /A RenInc=1
if not [%2]==[] set Prefix=%~2
if not [%3]==[] set /A NumLen=%3
if not [%4]==[] set /A Offset=%4
if not [%5]==[] set /A RenInc=%5
set RealExt=%~x1
set TempExt=%RealExt:.=.tmp_%
set DrvPath=%~dp1
if NOT defined Offset set /A Offset=1
if NOT defined RenInc set /A RenInc=1
:: Check for valid files to rename
for /f %%A in ('dir %1 /a-d /b 2^>nul^|find /c /v ""') do set RenCnt=%%A
if %RenCnt%==0 echo There are no "%1" files to rename. & goto :EOF
set /A RenMax=(Offset+(RenCnt*RenInc))-RenInc
:: Check if previous UNDO file exists
set ask=
if exist "%DrvPath%UndoRenumb.cmd" (
echo The last UNDO file "%DrvPath%UndoRenumb.cmd" is still usable,
set /p ask="do you wish to overwrite it? (Y/N) :"
)
if exist "%DrvPath%UndoRenumb.cmd" (
if /i [%ask%]==[Y] (del "%DrvPath%UndoRenumb.cmd") else (goto :EOF))
:: Routine to check the highest number used
:: and increase NumLen if required
set ask=
set count=0
:findlength
set /a count+=1
call set RenMaxLen=%%RenMax:~0,%count%%%
if not %RenMaxLen%==%RenMax% goto :findlength
if NOT defined NumLen set /a NumLen=%count%
if %NumLen% LSS %count% (
echo The Numeral Length has been changed from %NumLen% to %count%
echo to accomodate the highest numeral needed for the rename - %RenMax%
set /p ask="Continue? [Y/N] :"
set /a NumLen=count
)
if /i [%ask%]==[N] goto :EOF
:: Body of routine to pass each filename to the Renumb routine
:: then rename all files with a temp extension to the real extension
:start
for /F "tokens=*" %%A in ('dir %1 /b /on /a-d') do Call :Renumb "%%A"
Ren "%DrvPath%*%TempExt%" *%RealExt%
endlocal & set /A Offset=%Offset%& set /A RenInc=%RenInc%
goto :EOF
:: routine to do the renumbering and renaming
:Renumb
set RenNew=00000000000000000000%Offset%
call set RenNew=%%RenNew:~-%NumLen%%%
Ren %1 "%Prefix%%RenNew%%TempExt%"
>>"%DrvPath%UndoRenumb.cmd" echo Ren "%~dp1%Prefix%%RenNew%%RealExt%" %1
set /a Offset=Offset+RenInc
goto :EOF
:Usage
echo.Usage: %0 file.ext ["Pre fix"] [#NumLength] [#Begin] [#Increment]
echo.
echo.To rename files to a new name, consisting of a prefix
echo.followed by an incrementing numeral (and the original extension)
echo.
echo."Pre fix" - is the prefix for your files
echo. (use "" if no prefix is desired and other options needed)
echo.#NumLength - EG: using 3 adds 001 as the numeral
echo.
echo.#Begin - Number to start the renaming at
echo.
echo.#Increment - Number to add to successive elements
echo.
echo.Example: %~f0 *.jpg "Model Planes " 3
echo. will rename all JPG files to "Model Planes nnn.JPG"
echo. where nnn is a number from 001 to 999
echo.
echo.An UNDO batch file "UndoRenumb.cmd" is generated in the file directory
::echo.The Offset and Increment values are preserved between successive runs
echo.Arguments in brackets are optional but the order is important:
echo.I.E. If you need increment then all other arguments must be included.
::Renumber.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::::