2016-11-12 77 views
-1

我會喜歡這個助理。如何讀取文件名,刪除名稱和其他名稱,創建一個文件夾,並將文件移動到與nodejs文件夾

我想創建一個腳本,將讀/看文件夾。

拉出名

將文件移動到的文件夾,並組織好它。

實施例:

我有以該順序

../downloads/in.the.moment.s01e05.480p.mkv

../downloads/in文件.the.moment.s01e04.480p/in.the.moment.s01e04.480p.mkv

../downloads/boma.s04e04.mkv

../downloads/boma.s04e06/boma.s04e06.mkv

../downloads/things.falls.out.1080p/things.falls.out.1080p.mkv

,我想它像這樣移動和排列。

../series/in.the.moment/s01/in.the.moment.s01e04.480p.mkv

../series/in.the.moment/s01/in.the。 moment.s01e05.480p.mkv

../series/boma/s04/boma.s04e04.mkv

../series/boma/s04/boma.s04e06.mkv

../ movies/things.falls.out.1080p.mkv

回答

1

很好的閱讀和寫作ing文件非常簡單;你可以學習如何自己做到這一點。至於創建一個基於你在那裏的新路線,你可以像這樣一個一個映射文件:

function mapToNewPath(filename) { 
    // this regexp strips out different parts of the filename 
    // first capture group is for series name 
    // second capture group is for the season 
    // only matches series episodes 
    var matches = filename.match(/^(.*?)\.(s[0-9]*)e[0-9]*/); 

    var series = matches && matches[1]; 
    var season = matches && matches[2]; 

    if (series) { 
    return 'series/' + series + '/' + season + '/' + filename; 
    } 

    return 'movies/' + filename; 
} 
相關問題