tar压缩文件
来源:互联网 发布:ps4能不能安装windows 编辑:程序博客网 时间:2024/05/21 09:31
#!/usr/bin/env python3
import os,zipfile,tarfile
def Zip(target_dir):
os.chdir(target_dir)
target_file=raw_input('please input your compress file name: ')
tar = tarfile.open(target_file, "w")
while True:
zip_opt=raw_input("compress all the files in this dir choice y,add files by hand choice n (y/n): ")
filenames=[]
if zip_opt=='y':
filenames=os.listdir(os.getcwd())
#tar = tarfile.open(target_file, "w")
for name in filenames:
tar.add(name)
tar.close()
print("compress finished!")
break
elif zip_opt=='n':
while True:
aaa=raw_input('input (e) to exit,or input the file name you want compressing : ')
if aaa=='e':
break
else:
filenames.append(aaa)
print filenames
for name in filenames:
tar.add(name)
tar.close()
print("compress finished!")
break
else:
print("Please in put the character 'y' or 'n'")
#zip_opt=input("Will you zip all the files in this dir?(Choose 'n' you should add files by hand)y/n: ")
def Unzip(target_dir):
target_name=raw_input("Please input the filename you want uncompress :")
os.chdir(target_dir)
tar = tarfile.open(target_name)
tar.extractall(os.path.join(target_dir, os.path.splitext(os.path.splitext(target_name)[0])[0] ))
tar.close()
print("Unzip finished!")
def main():
opt=raw_input("welcome! compress choose 'y',uncompress choose 'n'.y/n: ")
while True:
if opt=='y':
zip_dir=raw_input("Please input the absdir you want put the compress file in:")
Zip(zip_dir)
break
elif opt=='n':
unzip_dir=raw_input("Please input the absdir you want put the compress file in or nothing is in the current dir):")
print unzip_dir
if unzip_dir=='':
Unzip(os.getcwd())
else:
Unzip(unzip_dir)
break
else:
print("Please input the character 'y' or 'n'")
opt=input("What are you gonna do?Zip choose 'y',unzip choose 'n'.y/n: ")
if __name__=='__main__':
main()
import os,zipfile,tarfile
def Zip(target_dir):
os.chdir(target_dir)
target_file=raw_input('please input your compress file name: ')
tar = tarfile.open(target_file, "w")
while True:
zip_opt=raw_input("compress all the files in this dir choice y,add files by hand choice n (y/n): ")
filenames=[]
if zip_opt=='y':
filenames=os.listdir(os.getcwd())
#tar = tarfile.open(target_file, "w")
for name in filenames:
tar.add(name)
tar.close()
print("compress finished!")
break
elif zip_opt=='n':
while True:
aaa=raw_input('input (e) to exit,or input the file name you want compressing : ')
if aaa=='e':
break
else:
filenames.append(aaa)
print filenames
for name in filenames:
tar.add(name)
tar.close()
print("compress finished!")
break
else:
print("Please in put the character 'y' or 'n'")
#zip_opt=input("Will you zip all the files in this dir?(Choose 'n' you should add files by hand)y/n: ")
def Unzip(target_dir):
target_name=raw_input("Please input the filename you want uncompress :")
os.chdir(target_dir)
tar = tarfile.open(target_name)
tar.extractall(os.path.join(target_dir, os.path.splitext(os.path.splitext(target_name)[0])[0] ))
tar.close()
print("Unzip finished!")
def main():
opt=raw_input("welcome! compress choose 'y',uncompress choose 'n'.y/n: ")
while True:
if opt=='y':
zip_dir=raw_input("Please input the absdir you want put the compress file in:")
Zip(zip_dir)
break
elif opt=='n':
unzip_dir=raw_input("Please input the absdir you want put the compress file in or nothing is in the current dir):")
print unzip_dir
if unzip_dir=='':
Unzip(os.getcwd())
else:
Unzip(unzip_dir)
break
else:
print("Please input the character 'y' or 'n'")
opt=input("What are you gonna do?Zip choose 'y',unzip choose 'n'.y/n: ")
if __name__=='__main__':
main()
0 0
- tar 压缩文件
- tar压缩文件
- tar.xz压缩文件解压
- tar命令压缩和解压缩文件
- Windows下创建.tar.gz压缩文件
- java压缩文件成tar.gz格式
- linux tar解压bz2, gz,zip压缩文件
- linux tar解压bz2, gz,zip压缩文件
- shell: tar, bz2, gz 等压缩文件
- Linux下解压tar.xz格式压缩文件
- Linux下解压 tar.xz 格式压缩文件
- linux的tar命令压缩和解压缩文件
- Linux下解压tar.xz格式压缩文件
- gz文件解压,tar命令压缩文件
- 在Linux下压缩文件 tar命令的使用
- 在Linux下压缩文件 tar命令的使用
- 在Linux下压缩文件 tar命令的使用
- 【转】在Linux下压缩文件 tar命令的使用
- uboot的第一阶段 start.S文件源码注释
- 转:展望未来,总结过去10年的程序员生涯,给程序员小弟弟小妹妹们的一些总结性忠告
- qml入门
- Unity4.x Terrain位置
- 查找一个字符串中各个字符出现的次数,用TreeMap实现
- tar压缩文件
- mapreduce作业reduce被大量kill掉
- oc NSString和NSMutableString基本用法
- 用Python解压缩文件
- Z-Stack 中ZigBee 设备的 IEEE 地址 的初始化,读取,设置
- 黑马程序员——JAVA反射机制基础
- PowerShell清空IIS日志
- python压缩与读取.tar.bz2压缩包
- 原型模式(ProtoType) - Java里的对象复制