Get folder size to continue

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nickodemos
Posts: 16
Joined: 29 Jan 2013 08:17

Get folder size to continue

#1 Post by nickodemos » 14 Mar 2019 00:03

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.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Get folder size to continue

#2 Post by aGerman » 15 Mar 2019 17:27

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

nickodemos
Posts: 16
Joined: 29 Jan 2013 08:17

Re: Get folder size to continue

#3 Post by nickodemos » 16 Mar 2019 23:01

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.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Get folder size to continue

#4 Post by aGerman » 17 Mar 2019 04:49

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

pieh-ejdsch
Posts: 239
Joined: 04 Mar 2014 11:14
Location: germany

Re: Get folder size to continue

#5 Post by pieh-ejdsch » 18 Mar 2019 15:03

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

nickodemos
Posts: 16
Joined: 29 Jan 2013 08:17

Re: Get folder size to continue

#6 Post by nickodemos » 19 Mar 2019 20:17

Image

ShadowThief
Expert
Posts: 1159
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Get folder size to continue

#7 Post by ShadowThief » 19 Mar 2019 23:47

con is a reserved filename. You shouldn't be able to make a folder with that name.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Get folder size to continue

#8 Post by aGerman » 20 Mar 2019 06:13

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

Code: Select all

for /f "tokens=3,4" %%a in ...
Steffen

nickodemos
Posts: 16
Joined: 29 Jan 2013 08:17

Re: Get folder size to continue

#9 Post by nickodemos » 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.'

Image

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Get folder size to continue

#10 Post by aGerman » 20 Mar 2019 10:37

Can't help out here, sorry. I have no clue at all what syntax this mktorrent thingy requires.

Steffen

nickodemos
Posts: 16
Joined: 29 Jan 2013 08:17

Re: Get folder size to continue

#11 Post by nickodemos » 20 Mar 2019 11:49

NP. Thanks for the assist. At least the ground work is laid in case anyone else can figure out the final steps.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Get folder size to continue

#12 Post by aGerman » 20 Mar 2019 12:14

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 ...

nickodemos
Posts: 16
Joined: 29 Jan 2013 08:17

Re: Get folder size to continue

#13 Post by nickodemos » 20 Mar 2019 17:51

That did the trick. It is now a fully running script. Thank you once again for taking the time.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Get folder size to continue

#14 Post by Squashman » 20 Mar 2019 22:00

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.'

Image
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.

Post Reply