我试图从我的电影中对我的电视节目进行排序,我认为最好的方法是通过电视节目季节和剧集标记来识别它们.
我所有的电视节目都有以下格式S00E00.
尝试了以下
if (Pos(IntToStr(I), SR.Name) > 0) and (Pos('S', SR.Name) > 0) then result := true;
但这不起作用,因为如果一部电影有一个标题含有's'和任何数字,它会复制它.
需要像字符串pos"字母s后跟整数,整数,字母e,整数,整数"那样结果:= true
无论剧集是S01E03还是S09E12都会复制.
.........................................
2015年12月22日编辑
.........................................
谢谢雷米认为它不那么容易.
这是澄清的程序.
procedure TForm7.TvShowCopy (Format: string);// Format would be .mp4 or whatever you're using but since the procedure searches for a name matching "S00E00" format I suppose you wouldn't need the format and could just use *.*. begin aTvshowFiles := TDirectory.GetFiles(STvshows,format,// aTVshowfiles is a TStringDynArray , STvshows is the Source directory for the TV shows. TSearchOption.soAllDirectories, function(const Path: string; const SR: TSearchRec):Boolean begin result:= TRegEx.IsMatch(SR.Name, 'S[0-9][0-9]E[0-9][0-9]') end); CopyFilesToPath(aTvshowFiles, DTvshows); end;
经过测试,看似有效.
正如罗恩在评论中提到的,你可以使用正则表达式:
uses ..., RegularExpressions; function ContainsSeasonAndEpisode(const Input: String): Boolean; begin Result := TRegEx.IsMatch(Input, 'S[0-9][0-9]E[0-9][0-9]'); // or: 'S\d\dE\d\d' end; ... Result := ContainsSeasonAndEpisode(SR.Name);
正如Ken在评论中提到的,您也可以使用MatchesMask()
,例如,如果您正在测试文件名:
uses ..., Masks; function ContainsSeasonAndEpisode(const Input: String): Boolean; begin Result := MatchesMask(Input, '*S[0-9][0-9]E[0-9][0-9]*'); end; ... Result := ContainsSeasonAndEpisode(SR.Name);
或者,您可以简单地手动比较输入字符串,例如:
uses ..., StrUtils; function ContainsSeasonAndEpisode(const Input: String): Boolean; begin Result := false; Idx := Pos('S', Input); while Idx <> 0 do begin if (Idx+5) > Length(Input) then Exit; if (Input[Idx+1] >= '0') and (Input[Idx+1] <= '9') and (Input[Idx+2] >= '0') and (Input[Idx+2] <= '9') and (Input[Idx+3] = 'E') and (Input[Idx+4] >= '0') and (Input[Idx+4] <= '9') and (Input[Idx+5] >= '0') and (Input[Idx+5] <= '9') then begin Result := true; Exit; end; Idx := PosEx('S', Input, Idx+1); end; end; ... Result := ContainsSeasonAndEpisode(SR.Name);