Batch zipping multiple files in single directory












0














I need to make batch script, which will work this way:



There is a folder with one hundred files. I need to make a script which is zipping every 4 files into single archive. Then all created archives must be zipped into one, big archive file. That must be all done by one script.



I tried to make it, but I haven't idea how to make it this way.



This is what I wrote first:



@ECHO ON
SET SourceDir=C:UsersRidaanDocumentssobol
SET DestDir=C:folderDestination

CD /D "C:Program Files7-Zip"
FOR /F "TOKENS=*" %%F IN ('DIR /B /A-D "%SourceDir%"') DO (
7z.exe a "%DestDir%%%~NF.zip" "%SourceDir%%%~NXF"
)
EXIT


And second:



@echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
robocopy C:folderDestination /COPY:DAT /V /XO /NJH /NP /R:1000 /W:10
7z u -mx9 "C:folderEnd.7z" "C:folderDestination"
rmdir C:folderEnd /Q /S

:END
pause









share|improve this question
























  • The idea is that you attempt the task. There seems to be nothing in your code which attempts to select groups of four files, so until you've researched and attempted it your question is off topic.
    – Compo
    Nov 11 at 18:06
















0














I need to make batch script, which will work this way:



There is a folder with one hundred files. I need to make a script which is zipping every 4 files into single archive. Then all created archives must be zipped into one, big archive file. That must be all done by one script.



I tried to make it, but I haven't idea how to make it this way.



This is what I wrote first:



@ECHO ON
SET SourceDir=C:UsersRidaanDocumentssobol
SET DestDir=C:folderDestination

CD /D "C:Program Files7-Zip"
FOR /F "TOKENS=*" %%F IN ('DIR /B /A-D "%SourceDir%"') DO (
7z.exe a "%DestDir%%%~NF.zip" "%SourceDir%%%~NXF"
)
EXIT


And second:



@echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
robocopy C:folderDestination /COPY:DAT /V /XO /NJH /NP /R:1000 /W:10
7z u -mx9 "C:folderEnd.7z" "C:folderDestination"
rmdir C:folderEnd /Q /S

:END
pause









share|improve this question
























  • The idea is that you attempt the task. There seems to be nothing in your code which attempts to select groups of four files, so until you've researched and attempted it your question is off topic.
    – Compo
    Nov 11 at 18:06














0












0








0







I need to make batch script, which will work this way:



There is a folder with one hundred files. I need to make a script which is zipping every 4 files into single archive. Then all created archives must be zipped into one, big archive file. That must be all done by one script.



I tried to make it, but I haven't idea how to make it this way.



This is what I wrote first:



@ECHO ON
SET SourceDir=C:UsersRidaanDocumentssobol
SET DestDir=C:folderDestination

CD /D "C:Program Files7-Zip"
FOR /F "TOKENS=*" %%F IN ('DIR /B /A-D "%SourceDir%"') DO (
7z.exe a "%DestDir%%%~NF.zip" "%SourceDir%%%~NXF"
)
EXIT


And second:



@echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
robocopy C:folderDestination /COPY:DAT /V /XO /NJH /NP /R:1000 /W:10
7z u -mx9 "C:folderEnd.7z" "C:folderDestination"
rmdir C:folderEnd /Q /S

:END
pause









share|improve this question















I need to make batch script, which will work this way:



There is a folder with one hundred files. I need to make a script which is zipping every 4 files into single archive. Then all created archives must be zipped into one, big archive file. That must be all done by one script.



I tried to make it, but I haven't idea how to make it this way.



This is what I wrote first:



@ECHO ON
SET SourceDir=C:UsersRidaanDocumentssobol
SET DestDir=C:folderDestination

CD /D "C:Program Files7-Zip"
FOR /F "TOKENS=*" %%F IN ('DIR /B /A-D "%SourceDir%"') DO (
7z.exe a "%DestDir%%%~NF.zip" "%SourceDir%%%~NXF"
)
EXIT


And second:



@echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
robocopy C:folderDestination /COPY:DAT /V /XO /NJH /NP /R:1000 /W:10
7z u -mx9 "C:folderEnd.7z" "C:folderDestination"
rmdir C:folderEnd /Q /S

:END
pause






batch-file






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 17:35









Mofi

27.5k83777




27.5k83777










asked Nov 11 at 17:18









Adrian Kozak

1




1












  • The idea is that you attempt the task. There seems to be nothing in your code which attempts to select groups of four files, so until you've researched and attempted it your question is off topic.
    – Compo
    Nov 11 at 18:06


















  • The idea is that you attempt the task. There seems to be nothing in your code which attempts to select groups of four files, so until you've researched and attempted it your question is off topic.
    – Compo
    Nov 11 at 18:06
















The idea is that you attempt the task. There seems to be nothing in your code which attempts to select groups of four files, so until you've researched and attempted it your question is off topic.
– Compo
Nov 11 at 18:06




The idea is that you attempt the task. There seems to be nothing in your code which attempts to select groups of four files, so until you've researched and attempted it your question is off topic.
– Compo
Nov 11 at 18:06












1 Answer
1






active

oldest

votes


















0














Just to give you an idea of counting files and




  • calculating the int of count/4 for the zip number

  • the modulus%4 for the file number (0..3) to determine if it's a new zip to create or to append to the zip.




:: Q:Test20181111SO_53251220.cmd
@Echo off&SetLocal EnableExtensions EnableDelayedExpansion

set Cnt=0
Set "SrcDir=X:YourPath"
For /F "delims=" %%A in ('Dir /B/A-D "%SrcDir%*"') do (
Set /A "File=Cnt%%4,Zip=Cnt/4,Cnt+=1"
Echo Cnt=!Cnt! File=!File! Zip=!Zip! File=%%A
)





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251220%2fbatch-zipping-multiple-files-in-single-directory%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Just to give you an idea of counting files and




    • calculating the int of count/4 for the zip number

    • the modulus%4 for the file number (0..3) to determine if it's a new zip to create or to append to the zip.




    :: Q:Test20181111SO_53251220.cmd
    @Echo off&SetLocal EnableExtensions EnableDelayedExpansion

    set Cnt=0
    Set "SrcDir=X:YourPath"
    For /F "delims=" %%A in ('Dir /B/A-D "%SrcDir%*"') do (
    Set /A "File=Cnt%%4,Zip=Cnt/4,Cnt+=1"
    Echo Cnt=!Cnt! File=!File! Zip=!Zip! File=%%A
    )





    share|improve this answer


























      0














      Just to give you an idea of counting files and




      • calculating the int of count/4 for the zip number

      • the modulus%4 for the file number (0..3) to determine if it's a new zip to create or to append to the zip.




      :: Q:Test20181111SO_53251220.cmd
      @Echo off&SetLocal EnableExtensions EnableDelayedExpansion

      set Cnt=0
      Set "SrcDir=X:YourPath"
      For /F "delims=" %%A in ('Dir /B/A-D "%SrcDir%*"') do (
      Set /A "File=Cnt%%4,Zip=Cnt/4,Cnt+=1"
      Echo Cnt=!Cnt! File=!File! Zip=!Zip! File=%%A
      )





      share|improve this answer
























        0












        0








        0






        Just to give you an idea of counting files and




        • calculating the int of count/4 for the zip number

        • the modulus%4 for the file number (0..3) to determine if it's a new zip to create or to append to the zip.




        :: Q:Test20181111SO_53251220.cmd
        @Echo off&SetLocal EnableExtensions EnableDelayedExpansion

        set Cnt=0
        Set "SrcDir=X:YourPath"
        For /F "delims=" %%A in ('Dir /B/A-D "%SrcDir%*"') do (
        Set /A "File=Cnt%%4,Zip=Cnt/4,Cnt+=1"
        Echo Cnt=!Cnt! File=!File! Zip=!Zip! File=%%A
        )





        share|improve this answer












        Just to give you an idea of counting files and




        • calculating the int of count/4 for the zip number

        • the modulus%4 for the file number (0..3) to determine if it's a new zip to create or to append to the zip.




        :: Q:Test20181111SO_53251220.cmd
        @Echo off&SetLocal EnableExtensions EnableDelayedExpansion

        set Cnt=0
        Set "SrcDir=X:YourPath"
        For /F "delims=" %%A in ('Dir /B/A-D "%SrcDir%*"') do (
        Set /A "File=Cnt%%4,Zip=Cnt/4,Cnt+=1"
        Echo Cnt=!Cnt! File=!File! Zip=!Zip! File=%%A
        )






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 18:15









        LotPings

        17.4k61532




        17.4k61532






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251220%2fbatch-zipping-multiple-files-in-single-directory%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()