Created
March 10, 2019 08:11
-
-
Save vizhen/3ae3a3fa54a05e5fd957100992e2fa4a to your computer and use it in GitHub Desktop.
视频文件剪切到同名文件夹里面
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import shutil | |
def list_type_files(path, types, flag): | |
files = [] | |
if os.path.isdir(path) is False: | |
print("路径错误!") | |
return | |
for f in os.listdir(path): | |
if os.path.isdir(os.path.join(path, f)): | |
#print("-- >"+ f) | |
if flag is True: | |
files.append(list_type_files(os.path.join(path, f), types, True)) | |
else: | |
file_type = str(f.split('.')[-1]).lower() | |
if file_type in types: | |
files.append(os.path.join(path, f)) | |
return files | |
if __name__ == '__main__': | |
#print(list_type_files("E:\\R18", ('mkv', 'avi', 'mp4', 'rm', 'rmvb', 'mpeg', 'iso'), True)) | |
movie_type = ('mkv', 'avi', 'mp4', 'rm', 'rmvb', 'mpeg', 'iso') | |
for movie in list_type_files("F:\\迅雷下载", movie_type, False): | |
dirn = str(movie.split('.')[0]) | |
if os.path.isdir(dirn) is False: | |
os.mkdir(dirn) | |
shutil.move(movie, dirn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment