问题描述
我正在尝试运行此特定的python脚本,以在子文件夹中创建.m3u文件,但它无法正常工作并给我一个错误,欢迎您提供任何帮助。 m3u文件是子文件夹内容的简单跟踪列表,具有指定的扩展名并以该子文件夹命名,如下所示(扩展名.aaa和.bbb只是示例):
文件1.aaa
文件2.aaa
文件1.bbb
文件2.bbb
这是一个名为makem3u.py的脚本(不是我的,我对python不太了解):
#!/usr/bin/python
"""This script will create an m3u file with a tracklist of each .aaa or .bbb
found in a subdirectory,then name the m3u after the subdirectory. This helps
with multiple disks for emulation.
"""
import os
import os.path
EXT = ['.aaa','.bbb']
cwd = os.getcwd()
dirs = os.listdir(cwd)
for d in dirs:
contents = os.listdir(os.path.join(cwd,d))
disks = [
os.path.join(d,f) for f in os.listdir(os.path.join(cwd,d))
if os.path.splitext(f)[-1] in EXT
]
if disks:
with open(os.path.join(cwd,'{d}.m3u'.format(d=d)),'wb') as m3u:
m3u.writelines(['{disk}\n'.format(disk=disk) for disk in disks])
当我尝试运行它时收到此错误:
Traceback (most recent call last):
File "makem3u.py",line 16,in <module>
contents = os.listdir(os.path.join(cwd,d))
NotADirectoryError: [WinError 267] The directory name is invalid: 'path\\to\\file\\makem3u.py'
Windows 10,Python 3.8.5,python已正确安装,并且PATH位于环境变量中,我可以很好地运行其他脚本
我做错了什么,该如何解决?是否有非Python替代方法(如创建.bat文件)来做到这一点?很抱歉有这么多问题,我对这些事情不屑一顾。预先谢谢你!
还有一种方法可以批量压缩子文件夹中的所有文件(生成的m3u +原始文件),并以该子文件夹命名每个zip文件?这是额外的,但如果可能的话会有所帮助
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)