windows - Batch Make 100MB Archive max with all files contained into a folder (Recursive) -


i looking create program zip (using 7zip) files contained folder (recursivly) archive until archive hits 100mb. whenever does, join in .csv file associated file, delete it, create new 1 next number , create new archive. should until files archived archive (number doesn't matter long files added archive)

my example not considering files inside sub-folders yet. (yeah, gotta start somewhere)

the example little counter-logical, remove last added file archive once sees it's bigger 100mb. problem is, don't think batch can evaluate output of archive before creating it, therefore it's little workaround. way manages find size of archive , afterwards determine if it's ok go or if done one.

i'm doing because need zip files being maxed out 100mb. doesn't matter if 10 or 20 .zip files, matters none bust 100mb. after we'll use output archives , upload them archive all.

as can see echo name,type,file,event newer file because headers required .csv file. required put .csv file every archive, , why once spots 100mb cap deletes last added file, put in .csv , afterwards deletes it.

i have taken care of unique file size, none of them going bigger 40mb, , lesser 40mb considered.

anyway have far doesn't want work, reason closes asap after doubleclick .bat

set /a modif=1 set "file=importationinfo" set "reqext=.csv" echo name,type,file,event> %file%%modif%%reqext% %%a in (*.*) ( if not %%~zi gtr 40999999 (     if /i not "%%~nxa"=="%~nx0" (         if /i not "%%~nxa"=="%file%%modif%%reqext%" (             /f "delims=" %%b in ("%%~dpa\.") (                 >>"%file%%modif%%reqext%" echo "%%~nxa","4","\%%~nxa","%id%"                 "c:\program files\7-zip\7z.exe" -tzip import%modif%.zip "%%~nxa"                 /f %%i in ("import%modif%.zip") set "size=%%~zi"                     echo %size%                     if %size% gtr 104857599 (                     echo bigger 104857599                              rem echo debugging                     "c:\program files\7-zip\7z.exe" d -tzip import%modif%.zip "%%~nxa"                     pause                     "c:\program files\7-zip\7z.exe" -tzip import%modif%.zip "%file%%modif%%reqext%"                     del %file%%modif%%reqext%                     set /a modif+=1                     echo name,type,file,event> %file%%modif%%reqext%                 ) else (                     echo not 100mb yet                     >>"%file%%modif%%reqext%" echo "%%~nxa","4","\%%~nxa","%id%" )                 )             )         )     ) ) 

that all. hope guys can me out on this. thanks. j-p.

edit : know possible ask maximum file size 7z , zip them alltogether, , it'll automatically create multiple archives .001 .002 ... filenames afterwards. in specific case option not ok, archives not used recreate these files archive them (upload using .zip format). therefore if files split 2 different archive, cause problems. why want join in new .csv in every archive.

you might test this:

@echo off &setlocal set "archive=test\archive" set "startfolder=%userprofile%" set /a maxsize=104857600  /f "tokens=1*delims=:" %%a in ('dir /s /b /a-d "%startfolder%" ^| findstr /n $') (     if %%~za gtr %maxsize% (echo "%%a" large (%%~za bytes^) &goto :eof)     set "$%%a=%%~fb"     set "filecount=%%a" ) set /a ptr=1 set /a anr=1 :loop call set "file=%%$%ptr%%%" echo adding "%file%" %archive%-%anr%.7z start /b /w "7zip" "7za" "%archive%-%anr%" "%file%" >nul||(echo error!&goto :eof)  %%a in ("%archive%-%anr%.7z") set "asize=%%~za" if %asize% gtr %maxsize% (     echo deleting "%file%" %archive%-%anr%.7z     start /b /w "7zip" "7za" d "%archive%-%anr%" "%file%" >nul||(echo error!&goto :eof)     set /a anr+=1 ) else (     set /a ptr+=1 ) if %ptr% leq %filecount% goto :loop echo %filecount% file(s) added in %anr% archive(s). 

note #1: script doesn't work = in file or path names
note #2: script terminate, if finds file size greater archive size
note #3: archive names created archive-1.7z, archive-2.7z...
note #4: because testing compression takes time, havn't tested much
note #5: because of special needs script works slowly
accepting answers: how work?.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -