所以我已經從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