-3

I'm trying to use shutil.make_archive but it's duplicating the folder name. Let me explain better:

My folder R360 to be ziped is located at: C:\Users\PycharmProjects\Project\media\SAE\R360\

What I am trying to do is: create a zip folder with this same name. So in the SAE directory, it should be the regular folder R360 and then R360.zip.

My code:

folder = C:\Users\PycharmProjects\Project\media\SAE\R360
mediaFolder = C:\Users\PycharmProjects\Project\media\
shutil.make_archive(f'{folder}', 'zip', f"{mediaFolder}SAE/", f"{folder.split('/')[-1]}/")

The R360.zip is being created normally but the problem is that the zip folder is like this:

C:\Users\PycharmProjects\Project\media\SAE\R360.zip\R360\...

What I really wanted:

C:\Users\PycharmProjects\Project\media\SAE\R360.zip\...

It shouldn't be that R360 inside the zip folder.

Felipe Dourado
  • 441
  • 2
  • 12
  • 1
    Is that actually your code? Your paths appear to be strings, but they're not quoted. – CrazyChucky Sep 09 '21 at 02:13
  • Yes, it's my code! It's kind of working but creating the folder itself inside the zip! I wish this R360 folder did not exist inside the R360.zip – Felipe Dourado Sep 09 '21 at 02:16
  • 1
    Are you sure you copied it correctly? `folder = C:\Users\PycharmProjects\Project\media\SAE\R360` isn't even valid Python, it would throw a syntax error. – CrazyChucky Sep 09 '21 at 08:02

1 Answers1

-2

I'd like to post my own question for other who are facing the same issue!

folder = C:\Users\PycharmProjects\Project\media\SAE\R360
mediaFolder = C:\Users\PycharmProjects\Project\media\
shutil.make_archive(f'{folder}/', 'zip', f"{mediaFolder}SAE/{folder.split('/')[-1]}")

This will create the zip file, without duplicating the folder itself inside the zip!

Felipe Dourado
  • 441
  • 2
  • 12