python循环解压rar文件
python循环解压rar文件
C:.
│ main.py
│
├─1_STL_算法简介
│ STL_算法简介.rar
│
└─2_STL_算法_填充新值
STL_算法_填充新值.rar
事情是这样的,下载了一套教学视频,文件夹命名规则是:“序号+视频名”,文件夹内是“视频名.rar”,上面选取了其中两个文件作为示例。这样看视频的时候就出现一个问题,每看一次都需要切换一次目录,解压一次文件,烦!
遂写main.py
import rarfile
import shutil
import os
path = os.getcwd()
allFile = os.listdir(path)
for dir in allFile:
if '.' not in dir:
dir2 = os.listdir(path+'\\'+dir)
for file in dir2:
if '.rar' in file:
rar = rarfile.RarFile(path+'\\'+dir+'\\'+file)
rar.extractall(path+'\\'+dir)
dir2 = os.listdir(path+'\\'+dir)
for file in dir2:
if '.wmv' in file:
print(dir)
print(file)
os.chdir(path+'\\'+dir)
os.rename(file, dir+'.wmv')
shutil.copy2(dir+'.wmv', path)
os.chdir(path)
出现问题:
Traceback (most recent call last):
File "C:\Python35\lib\site-packages\rarfile.py", line 2813, in custom_popen
creationflags=creationflags)
File "C:\Python35\lib\subprocess.py", line 676, in __init__
restore_signals, start_new_session)
File "C:\Python35\lib\subprocess.py", line 955, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\新建文件夹 (2)\main.py", line 14, in <module>
rar.extractall(path+'\\'+dir)
File "C:\Python35\lib\site-packages\rarfile.py", line 820, in extractall
self._extract(fnlist, path, pwd)
File "C:\Python35\lib\site-packages\rarfile.py", line 885, in _extract
p = custom_popen(cmd)
File "C:\Python35\lib\site-packages\rarfile.py", line 2816, in custom_popen
raise RarCannotExec("Unrar not installed? (rarfile.UNRAR_TOOL=%r)" % UNRAR_TOOL)
rarfile.RarCannotExec: Unrar not installed? (rarfile.UNRAR_TOOL='unrar')
下载UnRar.exe
链接:http://pan.baidu.com/s/1o8ObqCa 密码:dsru
放在当前文件夹,运行main.py。
目录树变为:
C:.
│ 1_STL_算法简介.wmv
│ 2_STL_算法_填充新值.wmv
│ main.py
│ UnRAR.exe
│
├─1_STL_算法简介
│ 1_STL_算法简介.wmv
│ STL_算法简介.rar
│
└─2_STL_算法_填充新值
2_STL_算法_填充新值.wmv
STL_算法_填充新值.rar
python循环解压rar文件的更多相关文章
- ubuntu解压rar文件
一般通过默认安装的ubuntu是不能解压rar文件的,只有在安装了rar解压工具之后,才可以解压.其实在ubuntu下安装rar解压工具是非常简 单的,只需要两个步骤就可以迅速搞定. ubuntu 下 ...
- CentOS解压rar文件
默认不能解压rar文件. 进官网下载:http://www.rarsoft.com/download.htm RAR 5.40 for Linux x64 安装: # tar -zxvf rarlin ...
- rar x 解压rar文件,提示permission denied
问题: 解压rar文件,提示
- Linux解压rar文件
Linux解压rar文件(unrar安装和使用,分卷解压) windows平台很多压缩文档为rar文件,那么怎么做到Linux解压rar文件(unrar安装和使用)? 简单,centos5安装unra ...
- linux(redhat)环境下,如何解压rar文件?
需求描述: 今天一个同事发过来一个压缩文件,让传送到linux服务器上,传上去之后,发现是rar格式的 之前没有解压过,就找了一些解压方法,在此记录下. 操作过程: 1.下载rar在linux环境下的 ...
- java 提取(解压)rar文件中特定后缀的文件并保存到指定目录
内容简介 本文主要介绍使用junrar来提取rar压缩文件中特定后缀(如:png,jpg)的文件并保存到指定目录下. 支持v4及以下版本压缩文件,不支持v5及以上. 在rar文件上右键,查看属性,在压 ...
- Ubuntu 16.04安装unrar解压RAR文件
除了7zip:http://www.cnblogs.com/EasonJim/p/7124306.html之外,还可以安装unrar进行解压RAR文件. 安装 sudo apt-get install ...
- linux 下面压缩、解压.rar文件
一,解压问题 在网上下东西的时候,经常会遇到.rar后缀的文件,我用tar解压,解压不出,上网找啊找,一直没找到什么合适的工具来压缩和解压.rar后缀的文件,现在我找到了. 二,rar和unrar安装 ...
- linux中解压rar文件
linux平台默认是不支持RAR文件的解压,需要安装linux版本的RAR压缩软件,下载地址为:http://www.rarlab.com/download.htm 下载之后进行解压之后,进入rar目 ...
随机推荐
- rhce 第十题 配置NFS服务
配置NFS服务 在system1配置NFS服务,要求如下: 以只读的方式共享目录/public,同时只能被group8.example.com域中的系统访问 以读写的方式共享目录/protected, ...
- poj2528(线段树+离散化)
题目链接:https://vjudge.net/problem/POJ-2528 题意:在区间[1,1e7]内染色,依次染n(<=1e4)中颜色,给出每种颜色染色的范围,可重叠,求最终有多少种颜 ...
- mysql与cmd,中文乱码
图中第一次select, 通过navicat插入表中的, 下面的这次select结果,是直接在命令行中插入的,中文就显示了两个问号...搞不懂咋回事..我是win10家庭版系统.....希望各位道友谨 ...
- flutter Dialog里ListView的问题
showDialog( context: context, builder: (ctx) { return // Dialog( // child: Container( // padding: Ed ...
- find用法详解
一.find的用法 find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [express ...
- Ocelot的学习
Ocelot是一个用.NET Core实现并且开源的API网关,它功能强大,包括了:路由.认证.鉴权.简单缓存.限流熔断.负载均衡器等.简单的来说Ocelot是一堆的asp.net core midd ...
- Json格式获取接口返回的值
关键字:Set Variable Get Json Value to json Get From Dictionary 具体关键字用法不再说明,可百度一下 ...
- NC 自定义项参照设置为查询条件
select * from pub_query_condition where pk_templet in (select id from pub_query_templet where node_c ...
- What is REST API
What is REST REST is acronym for REpresentational State Transfer. It is architectural style for dist ...
- Linux关闭防火墙命令
下面是red hat/CentOs7关闭防火墙的命令! 1:查看防火状态 systemctl status firewalld service iptables status 2:暂时关闭防火墙 s ...