I am trying to do the following: command line compress a file from C:\TestFolder\file.txt (source location) and on the same command or bat file put that compressed file in (a destination folder) C:\DestinationFolder\file.7z.

My scenario applies to our real life point of sale system. We have an .mdb file that lives in a folder in the C:\ and I need to compress and copy the compressed file to a destination folder in the C:\. However, we do not want anything to occur to the original .mdb file in the source folder.

Let me know if I need to further clarify.

  • Have a look here at this - stackoverflow.com/a/20225465/175063 – Leptonator Aug 26 '15 at 15:57
  • @Leptonator Your link is about "extracting". This questions is about "adding" – DavidPostill Aug 26 '15 at 16:26
  • @DavidPostill you are correct.. I was going the wrong way.. Try this and this will insure the arguments are in place especially in a Batch Script: 7z -t7z -y a "C:\DestinationFolder\file.7z" "c:\file.mdb" – Leptonator Aug 26 '15 at 16:32
  • @Leptonator That's pretty much what my answer says ;) -t7z and -y are optional. – DavidPostill Aug 26 '15 at 16:33
  • Completely agreed. However, I like to insure that there is no failure.. We have to send reports to over 1000 customers a day, so I utilize complete overkill with switches, quotes, etc. Cannot have any failure whatsoever. – Leptonator Aug 26 '15 at 16:35

Compress and copy to destination folder

Use the following command:

7z a C:\DestinationFolder\file.7z c:\file.mdb


  • a is add
  • See link below for the full manual for the command line version of 7z.

Further reading

  • If I create a batch file for this and create a scheduled task will I run into any issues if the user on the PC is not logged in? I have had bad experiences with scheduled task that is why I am wondering if this is possible. – Isaiah Melendez Aug 26 '15 at 16:23
  • @IsaiahMelendez It should be fine. Try it, and if you can't get it working ask a new question. – DavidPostill Aug 26 '15 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.