so I decided to make a batch to generate possible list of movies that would fit in a certain dvd.
the problem is it sometimes returns negative numbers as the size of the files
@set @x=0 /*
@echo off
@set _thisbatchscript="%~f0"
@setlocal enabledelayedexpansion
@set max=8525510083
@set "parentfolder=%__CD__%"
@set flenght=1
@for /r . %%g in (*.*) do (
@call :gera "%%g"
@set "var=%%g"
@set var=!var:%parentfolder%=!
@set fname[!flenght!]=!var!
@set /a flenght=!flenght!+1
)
@set /a flenght=!flenght!-1
@set movielgt=1
@for /l %%a in (1,1,!flenght!) do (
if !fext[%%a]!==.avi (
@set movienm[!movielgt!]=!fname[%%a]!
@set moviesz[!movielgt!]=!fsize[%%a]!
@set ftemp=!fname[%%a]!
@set ftemp=!ftemp:.avi=!
@set movienoext[!movielgt!]=!ftemp!
@set /a movielgt=!movielgt!+1
)
)
@set /a movielgt=!movielgt!-1
@set subtitlelgt=1
@for /l %%a in (1,1,!flenght!) do (
@if !fext[%%a]!==.srt (
@set subtitlenm[!subtitlelgt!]=!fname[%%a]!
@set subtitlesz[!subtitlelgt!]=!fsize[%%a]!
@set ftemp=!fname[%%a]!
@set ftemp=!ftemp:.srt=!
@set subtitlenoext[!subtitlelgt!]=!ftemp!
@set /a subtitlelgt=!subtitlelgt!+1
)
)
@set /a subtitlelgt=!subtitlelgt!-1
@for /l %%a in (1,1,!movielgt!) do (
@for /l %%b in (1,1,!subtitlelgt!) do (
@if !movienoext[%%a]!==!subtitlenoext[%%b]! (
@set /a moviesz[%%a]=!moviesz[%%a]!+!subtitlesz[%%b]!
)
)
)
set resultlgt=0
for /l %%a in (1,1,!movielgt!) do (
if !moviesz[%%a]! LEQ %max% (
set _tempresultsz=0
set _tempresultnm=
set tamanho=
for /l %%b in (%%a,1,!movielgt!) do (
set /a tamanho+=!moviesz[%%b]!
if !tamanho! LEQ %max% (
set /a _tempresultsz+=!moviesz[%%b]!
set _tempresultnm=!_tempresultnm! !movienm[%%b]!
call :resultpush "!_tempresultnm!" !_tempresultsz!
)
)
)
)
echo tamanho;arquivos
for /l %%a in (1,1,!resultlgt!) do (
echo !result[%%a]sz!;!result[%%a]nm!
)
:gera
@set fsize[!flenght!]=%~z1
@set fext[!flenght!]=%~x1
@goto :EOF
:resultpush
@set /a resultlgt+=1
for /f "tokens=* delims= " %%a in ("%~1") do set str=%%a
@set result[!resultlgt!]nm=%str%
REM for /f "delims=" %%i in ('cscript //Nologo //E:jscript %_thisbatchscript% %2') do set _tamanho=%%i
@set result[!resultlgt!]sz=%2
@goto :EOF
REM start of javascript (not in use(too slow to run on evey interation))
goto:EOF */
var Size=WScript.Arguments(0);
var result=Size+" Bytes"
if(Size>=1024){
result=(Size/1024)+" KB";
}
if(Size>=1048576){
result=(Size/1048576)+" MB";
}
if(Size>=1073741824){
result=(Size/1073741824)+" GB";
}
if(Size>=1099511627776){
result=(Size/1099511627776)+" TB";
}
WSH.echo(result);
so yeah, that's the code basically it gets the full list of files in the folder and sub folders from the path it got called, and them iterate over it looking for .avi and .srt files, them it sums the size of .avi files with the size of .str files that have the same folder path and file name, and lastly it iterates over again calculating the possible list of files that could fit in the dvd