Batch zipping multiple files in single directory
up vote
0
down vote
favorite
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
add a comment |
up vote
0
down vote
favorite
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
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
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
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
batch-file
edited Nov 11 at 17:35
Mofi
27.2k83676
27.2k83676
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
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
)
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
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
)
add a comment |
up vote
0
down vote
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
)
add a comment |
up vote
0
down vote
up vote
0
down vote
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
)
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
)
answered Nov 11 at 18:15
LotPings
16.5k61531
16.5k61531
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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