Jump to content

AutoIt - using 7z cmd adds parent folder to archive

Recommended Posts

Hello world! I'm trying to add to an archive with this AutoIt code:

$CompressPath = c:\directory\subdirectory\path_to_files

$CmdChange = "cd " & $CompressPath
RunWait(@ComSpec & " /c " & $CmdChange, "", @SW_HIDE)

$pathZIP = c:\path_to_archive
$filename = archive_name.zip

$CmdCompress = "7z a " & $pathZIP & "\" & $filename & " .\* -r"
RunWait(@ComSpec & " /c " & $CmdCompress, "", @SW_HIDE)

This actually adds all of c:\directory to the archive, instead of just the contents of c:\directory\subdirectory\path_to_files, like it 'should'.

However, when I try this code in cmd directly, it works correctly, meaning only the contents of c:\directory\subdirectory\path_to_files are added to the archive, and nothing else:

cd c:\directory\subdirectory\path_to_files
7z a c:\path_to_archive\archive_name.zip .\* -r

Any ideas as to what I'm doing wrong?

Edited by lukedeloosh
Link to post
Share on other sites


The reason yours fails is that your running two separate cmd processes, you need to combine them like below (untested):

Global $sCompressPath = "c:\directory\subdirectory\path_to_files"
Global $sZipPath = "c:\path_to_archive"
Global $sZipName = "archive_name.zip"
$CmdChange = RunWait(@ComSpec & " /c cd " & $sCompressPath & "&&7z a " & $sZipPath & "\" & $sZipName & " .\* -r", "", @SW_HIDE)


Edited by Subz
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...