Page 1 of 1
Get folder size to continue
Posted: 14 Mar 2019 00:03
by nickodemos
Code: Select all
@echo off
SET OPT= -a "http://www.mvgroup.org:2710/announce" -l22
if exist %%1.torrent (
rem file exists
) else (
FOR /D %%I IN (*.*) DO mktorrent.exe %opt% "%%I"
)
Right now this is a script I use to create torrents that are in a directory. The -l22 is setting the piece size at 4mb. As the folders I am using can be anywhere from 500mb to 500gb using a one size fits all approach is not ideal.
So what I wanted to ask help on is being able to scan the size of the folder first to be able to set the needed size to get the idea piece size.
l15 Files up to 50MiB
l16 Files 50MiB to 150MiB
l17 Files 150MiB to 350MiB
l18 Files 350MiB to 512MiB
l19 Files 512MiB to 1.0GiB
l20 Files 1.0GiB to 2.0GiB
l21 Files 2.0GiB to 4.0GiB
l22 Files 4.0GiB to 8.0GiB
l23 Files 8.0GiB to 16.0GiB
l24 Files 16.0GiB to 512GiB
If I am not clear please ask.
Re: Get folder size to continue
Posted: 15 Mar 2019 17:27
by aGerman
This code only displays the command lines. Remove ECHO at the end of the subroutine to execute the command lines.
Code: Select all
@echo off &setlocal
:: main code
set OPT=-a "http://www.mvgroup.org:2710/announce"
for /d %%i in (*) do (
set "folder=%%~fi"
call :proc_folder
)
PAUSE
exit /b
:: subroutine
:proc_folder
REM get size and dimension
for /f "tokens=2,3" %%a in ('robocopy "%folder%" "%temp%\con" /l /s /r:0 /nfl /ndl /njh^|find "Bytes"') do (
set "unit=%%b"
REM strip decimals
for /f "delims=." %%c in ("%%a") do set "size=%%c"
)
REM determine the value for the -l option
if "%unit%"=="t" ( REM Terabytes
echo "%folder%" too large
exit /b
) else if "%unit%"=="g" ( REM Gigabytes
if %size% geq 512 (
echo "%folder%" too large
exit /b
) else if %size% geq 16 (
set "L=-l24"
) else if %size% geq 8 (
set "L=-l23"
) else if %size% geq 4 (
set "L=-l22"
) else if %size% geq 2 (
set "L=-l21"
) else if %size% geq 1 (
set "L=-l20"
) else (
set "L=-l19"
)
) else if "%unit%"=="m" ( REM Megabytes
if %size% geq 512 (
set "L=-l19"
) else if %size% geq 350 (
set "L=-l18"
) else if %size% geq 150 (
set "L=-l17"
) else if %size% geq 50 (
set "L=-l16"
) else (
set "L=-l15"
)
) else ( REM less
set "L=-l15"
)
ECHO mktorrent.exe %OPT% %L% "%folder%"
exit /b
Steffen
Re: Get folder size to continue
Posted: 16 Mar 2019 23:01
by nickodemos
If I remove ECHO I get :
Code: Select all
Error creating '/cygdrive/d/SeasonPack/D:\SeasonPack\Worlds.Busiest.Cities.S01.DVDRip.x264-GHOULS.torrent': No such file or directory
Something is throwing an error.
If I leave ECHO I get:
Code: Select all
mktorrent.exe -a "http://www.mvgroup.org:2710/announce" -l15 "D:\SeasonPack\nadiyas.british.food.adventure.s01.720p.hdtv.x264-qpel"
mktorrent.exe -a "http://www.mvgroup.org:2710/announce" -l15 "D:\SeasonPack\Top.Gear.S24.HDTV.x264-MTB"
mktorrent.exe -a "http://www.mvgroup.org:2710/announce" -l15 "D:\SeasonPack\Worlds.Busiest.Cities.S01.DVDRip.x264-GHOULS"
Runs through as you would think it should but all length size is set to -l15 on everything it does.
Re: Get folder size to continue
Posted: 17 Mar 2019 04:49
by aGerman
Pick one folder and run only the robocopy command in a cmd shell. Like that:
Code: Select all
robocopy "D:\SeasonPack\Top.Gear.S24.HDTV.x264-MTB" "%temp%\con" /l /s /r:0 /nfl /ndl /njh
Let me know what output you're facing.
Steffen
Re: Get folder size to continue
Posted: 18 Mar 2019 15:03
by pieh-ejdsch
nickodemos wrote: ↑16 Mar 2019 23:01
Code: Select all
Error creating '/cygdrive/d/SeasonPack/D:\SeasonPack\Worlds.Busiest.Cities.S01.DVDRip.x264-GHOULS.torrent': No such file or directory
This isn't a named fullpath!
check this line for double Quotes.
Phil
Re: Get folder size to continue
Posted: 19 Mar 2019 20:17
by nickodemos
Re: Get folder size to continue
Posted: 19 Mar 2019 23:47
by ShadowThief
con is a reserved filename. You shouldn't be able to make a folder with that name.
Re: Get folder size to continue
Posted: 20 Mar 2019 06:13
by aGerman
Haha, yes. I picked con explicitly because it is a reserved name in order to make sure that there is no existing folder with already existing files that are the same as in the folder that shall be processed. But that's just an annoying message which doesn't cause the real problem.
The actual problem is that you have an additional token. In your output it's "Bytes :" while it is "Bytes:" (without the space) if I run robocopy. That means you have to update the token numbers
Steffen
Re: Get folder size to continue
Posted: 20 Mar 2019 10:12
by nickodemos
Now the folder size is being chosen.
Yet we are back to this once I take the echo out and try and make the torrents.'
Re: Get folder size to continue
Posted: 20 Mar 2019 10:37
by aGerman
Can't help out here, sorry. I have no clue at all what syntax this mktorrent thingy requires.
Steffen
Re: Get folder size to continue
Posted: 20 Mar 2019 11:49
by nickodemos
NP. Thanks for the assist. At least the ground work is laid in case anyone else can figure out the final steps.
Re: Get folder size to continue
Posted: 20 Mar 2019 12:14
by aGerman
Maybe it's just set "folder=%%~i" instead of set "folder=%%~fi" because the utility seems to prepend a url that somehow contains the current directory. Just try a little ...
Re: Get folder size to continue
Posted: 20 Mar 2019 17:51
by nickodemos
That did the trick. It is now a fully running script. Thank you once again for taking the time.
Re: Get folder size to continue
Posted: 20 Mar 2019 22:00
by Squashman
nickodemos wrote: ↑20 Mar 2019 10:12
Now the folder size is being chosen.
Yet we are back to this once I take the echo out and try and make the torrents.'
You know you can copy and paste text from the console. That is much quicker then making a screen shot and consumes much less resources on the server and bandwidth.