找到丢失的顺序文件

时间:2016-11-10 19:04:14

标签: sql batch-file

我试图从我的电脑中删除包含电视剧集摘要文件的文件名。

有超过200个(电视节目)目录,每个节目都有每个季节的子文件夹,每个季节子文件夹包含每个剧集的拼写文件。 例:

G:\TV_Shows\The BlackList\02\The.Blacklist.Season02Episode05.properties

是否可以使用SQL和批处理文件查看每个目录并查找最大集编号并输出该编号下未找到的任何剧集?
我知道这不是万无一失的,如果最大的话。情节缺失它不会是正确的,但我认为这将是一个可接受的风险。

对此有任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

不,SQL不会帮助您找到丢失的文件,除非您在SQL数据库中有一些信息。

如果平面文件中有文件名列表,可以将它们加载到SQL数据库表中。

然后针对该表编写SQL查询。但字符串操作 不是SQL的强项。

答案 1 :(得分:0)

尝试以下脚本(请参阅注释以获取帮助):

@echo off
setlocal EnableExtensions DisableDelayedExpansion

::/* Facts/Restrictions:
::files must be named like `<show-name>.Season<season-num>Episode<episode-num>.properties`;
::the `<show-name>` portion must not contain `.Season` on its own,
::the `Episode` portion must follow the `.Season<season-num>` part;
::`<season-num>` and `<episode-num>` must begin at 1 and must not hold more than nine figures;
::`<season-num>` portion is checked against name of parent directory for numeric equality;
::`<show-name>` portion is not checked against name of parent directory of parent directory;
::`INFO:` outputs are returned at STDOUT and show number of shows/seasons/episodes;
::`ERROR:` outputs are returned at STDERR and indicate missing seasons/episodes;
::the desired numbers of seasons/episodes are unknown, so the last ones missing are undetected; */

rem // Define constants here:
set "_ROOTDIR=G:\TV_Shows"  & rem // (root directory containing all TV shows)
set "_PATTERN=*.properties" & rem // (file pattern to search in season directories)
set "_SEASONS=.Season"      & rem // (file name portion preceding season number)
set "_EPISODE=Episode"      & rem // (file name portion preceding episode number)

rem // Clear arrays:
for /F "delims==" %%F in ('2^> nul set SIZE[') do set "%%F="
for /F "delims==" %%F in ('2^> nul set NAME[') do set "%%F="

rem // Accumulate TV show information:
set /A "SIZE=0"
for /D %%C in ("%_ROOTDIR%\*") do (
    set /A "SIZE+=1"
    setlocal EnableDelayedExpansion
    for %%I in ("!SIZE!") do (
        endlocal
        set "SHOW=%%~nxC"
        for /D %%D in ("%%~C\*") do (
            set "SEASON1=%%~nxD"
            setlocal EnableDelayedExpansion
            for /F "tokens=* delims=0" %%E in ("!SEASON1!") do set "SEASON1=%%E"
            set /A "SEASON1+=0"
            for %%J in ("!SEASON1!") do (
                endlocal
                set /A "SIZE[%%~I_%%~J]=0"
                for %%F in ("%%~D\%_PATTERN%") do (
                    set "FILE=%%~nxF"
                    setlocal EnableDelayedExpansion
                    set "SEASON2=!FILE:*%_SEASONS%=1!"
                    set "SEASON2=!SEASON2:*%_SEASONS%=1!"
                    set "EPISODE=!SEASON2:*%_EPISODE%=1!"
                    set /A "SEASON2+=0, EPISODE+=0"
                    for /F "tokens=* delims=0" %%E in ("!SEASON2:~1!") do set "SEASON2=%%E"
                    for /F "tokens=* delims=0" %%E in ("!EPISODE:~1!") do set "EPISODE=%%E"
                    set /A "SEASON2+=0, EPISODE+=0"
                    for %%K in ("!EPISODE!") do (
                        if !SEASON2! NEQ %%~J (
                            >&2 echo ERROR: Show %%~I, "!SHOW!": season %%~J folder contains season !SEASON2! file^^!
                        ) else (
                            endlocal
                            set "NAME[%%~I_%%~J_%%~K]=%%~nxC"
                            setlocal EnableDelayedExpansion
                            if !SIZE[%%~I_%%~J]! LSS %%~K (
                                endlocal
                                set /A "SIZE[%%~I_%%~J]=%%~K"
                                setlocal EnableDelayedExpansion
                            )
                        )
                    )
                    endlocal
                )
                setlocal EnableDelayedExpansion
                if !SIZE[%%~I]! LSS %%~J (
                    endlocal
                    set /A "SIZE[%%~I]=%%~J"
                ) else endlocal
            )
        )
        set "NAME[%%~I]=%%~nxC"
    )
)

rem // Validate TV show information:
setlocal EnableDelayedExpansion
echo(INFO:  %SIZE% shows in total.
for /L %%I in (1,1,%SIZE%) do (
    if defined SIZE[%%I] (
        echo(INFO:  Show %%I, "!NAME[%%I]!": !SIZE[%%I]! seasons.
        for /L %%J in (1,1,!SIZE[%%I]!) do (
            if defined SIZE[%%I_%%J] (
                if !SIZE[%%I_%%J]! GTR 0 (
                    echo(INFO:  Show %%I, "!NAME[%%I]!"; season %%J: !SIZE[%%I_%%J]! episodes.
                    for /L %%K in (1,1,!SIZE[%%I_%%J]!) do (
                        if not defined NAME[%%I_%%J_%%K] (
                            >&2 echo(ERROR: Show %%I, "!NAME[%%I]!"; season %%J: episode %%K missing^^!
                        )
                    )
                ) else (
                    >&2 echo(ERROR: Show %%I, "!NAME[%%I]!"; season %%J: no episodes defined^^!
                )
            ) else (
                >&2 echo(ERROR: Show %%I, "!NAME[%%I]!": season %%J missing^^!
            )
        )
    ) else (
        >&2 echo(ERROR: Show %%I, "!NAME[%%I]!": no seasons defined^^!
    )
)
endlocal

endlocal
exit /B