help! how to compress file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
luckejuin
Posts: 1
Joined: 28 Apr 2020 04:30

help! how to compress file

#1 Post by luckejuin » 28 Apr 2020 04:31

hello,

I want to compress a specific folder and togerther with a file..
let's say I'm gonna zip a file

ex.

in my desktop i have this structure

inside my compress folder I have this

Fruits
- Folder A
- a.txt
- b.txt
- Folder B
- a.txt
-b.txt

a.bin
b.bin
c.bin

I want to zip Fruits folder + b.bin into a one zip file ex.hellow.zip
then delete Fruits folder and b.bin

I think I get what I want but the problem I can't delete the Fruit folder and it's sub folder

@echo off
:compress
set path=Fruits
set path2=b.bin
set z=compressed.zip
7z.exe a -tzip compressed.zip "%path%"
7z.exe a -tzip compressed. zip "%path2%"

if exist "%path%" (
for /d %%p in ("%path%"\*.*") do rmdir "%%p" /s /Q
del /s /q %path%\*.*



thank you

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

Re: help! how to compress file

#2 Post by ShadowThief » 28 Apr 2020 09:42

%PATH% is a system variable and it holds the location of every important file on your computer. Please don't overwrite that value and definitely don't delete anything from it.

scavenger
Posts: 18
Joined: 23 May 2015 13:51
Contact:

Re: help! how to compress file

#3 Post by scavenger » 19 May 2020 22:17

using your variables,

Code: Select all

@echo off
:compress
set folder=Fruits
set file=b.bin
set z=compressed.zip

7z.exe a %z% %folder% %file%
if %ERRORLEVEL% EQU 0 rd /s /q %folder% & del /q %file%

Post Reply