所以我已经从Coursera下载了“Introduction to computer networks”课程的mp4和srt文件。但mp4和srt文件的名称之间略有差异。如何编写一个程序来重命名mp4文件以匹配srt文件的名称?
文件名样本如下:
1 - 1 - 1-1 Goals and Motivation (1253).mp4
1 - 1 - 1-1 Goals and Motivation (12_53).srt
1 - 2 - 1-2 Uses of Networks (1316).mp4
1 - 2 - 1-2 Uses of Networks (13_16).srt
1 - 3 - 1-3 Network Components (1330).mp4
1 - 3 - 1-3 Network Components (13_30).srt
1 - 4 - 1-4 Sockets (1407).mp4
1 - 4 - 1-4 Sockets (14_07).srt
1 - 5 - 1-5 Traceroute (0736).mp4
1 - 5 - 1-5 Traceroute (07_36).srt
1 - 6 - 1-6 Protocol Layers (2225).mp4
1 - 6 - 1-6 Protocol Layers (22_25).srt
1 - 7 - 1-7 Reference Models (1409).mp4
1 - 7 - 1-7 Reference Models (14_09).srt
1 - 8 - 1-8 Internet History (1239).mp4
1 - 8 - 1-8 Internet History (12_39).srt
1 - 9 - 1-9 Lecture Outline (0407).mp4
1 - 9 - 1-9 Lecture Outline (04_07).srt
2 - 1 - 2-1 Physical Layer Overview (09_27).mp4
2 - 1 - 2-1 Physical Layer Overview (09_27).srt
2 - 2 - 2-2 Media (856).mp4
2 - 2 - 2-2 Media (8_56).srt
2 - 3 - 2-3 Signals (1758).mp4
2 - 3 - 2-3 Signals (17_58).srt
2 - 4 - 2-4 Modulation (1100).mp4
2 - 4 - 2-4 Modulation (11_00).srt
2 - 5 - 2-5 Limits (1243).mp4
2 - 5 - 2-5 Limits (12_43).srt
2 - 6 - 2-6 Link Layer Overview (0414).mp4
2 - 6 - 2-6 Link Layer Overview (04_14).srt
2 - 7 - 2-7 Framing (1126).mp4
2 - 7 - 2-7 Framing (11_26).srt
2 - 8 - 2-8 Error Overview (1745).mp4
2 - 8 - 2-8 Error Overview (17_45).srt
2 - 9 - 2-9 Error Detection (2317).mp4
2 - 9 - 2-9 Error Detection (23_17).srt
2 - 10 - 2-10 Error Correction (1928).mp4
2 - 10 - 2-10 Error Correction (19_28).srt
我想重命名的MP4文件匹配SRT文件,所以当我玩的影片,VLC可以自动加载字幕。什么人讨论算法来做到这一点?您也可以使用任何语言提供解决方案代码,因为我熟悉许多编程语言。但是python和C++更可取。
编辑: 感谢所有回复的人。我知道重命名srt文件比其他方式更容易。但我认为重命名mp4文件会更有趣。有什么建议么?
错误,只是['glob'](http://docs.python.or g/2/library/glob.html)所有'.str'并删除下划线?这就像十条蟒蛇线一样。 – Zeta 2013-04-06 07:41:07
该算法很简单:对于每个mp4文件,找到其相应的srt文件(1),并将其重命名为mp4文件具有的同名文件,但使用另一个扩展名。你应该继续尝试。 (1)不应该很难,因为您在文件名的第一个字段中具有识别信息。 – Mariano 2013-04-06 07:47:34