私は、ファイル内の既知のキーワードを調べることによって、ビデオファイルをフォルダに分類するスクリプトを作成しています。キーワードの量が制御不能になるにつれて、スクリプトは非常に遅くなり、各ファイルが処理されるまで数秒かかる。キーワードに基づいてファイルをソートするには、さらにデータベースとソリューションが必要です
@echo off
cd /d d:\videos\shorts
if /i not "%cd%"=="d:\videos\shorts" echo invalid shorts dir. && exit /b
:: auto detect folder name via anchor file
for /r %%i in (*spirit*science*chakras*) do set conspiracies=%%~dpi
if not exist "%conspiracies%" echo conscpiracies dir missing. && pause && exit /b
for /r %%i in (*modeselektor*evil*) do set musicvideos=%%~dpi
if not exist "%musicvideos%" echo musicvideos dir missing. && pause && exit /b
for %%s in (*) do set "file=%%~nxs" & set "full=%%s" & call :count
for %%v in (*) do echo can't sort "%%~nv"
exit /b
:count
set oldfile="%file%"
set newfile=%oldfile:&=and%
if not %oldfile%==%newfile% ren "%full%" %newfile%
set count=0
set words= & rem
echo "%~n1" | findstr /i /c:"music" >nul && set words=%words%, music&& set /a count+=1
echo "%~n1" | findstr /i /c:"official video" >nul && set words=%words%, official video&& set /a count+=2
set words=%words:has, =has %
set words=%words: , =%
if not %count%==0 echo "%file%" has "%words%" %count%p for music videos
set musicvideoscount=%count%
set count=0
set words= & rem
echo "%~n1" | findstr /i /c:"misinform" >nul && set words=%words%, misinform&& set /a count+=1
echo "%~n1" | findstr /i /c:"antikythera" >nul && set words=%words%, antikythera&& set /a count+=2
set words=%words:has, =has %
set words=%words: , =%
if not %count%==0 echo "%file%" has "%words%" %count%p for conspiracies
set conspiraciescount=%count%
set wanted=3
set winner=none
:loop
:: count points and set winner (in case of tie lowest in this list wins, sort accordingly)
if %conspiraciescount%==%wanted% set winner=%conspiracies%
if %musicvideoscount%==%wanted% set winner=%musicvideos%
set /a wanted+=1
if not %wanted%==15 goto loop
if not "%winner%"=="none" move "%full%" "%winner%" >nul && echo "%winner%%file%" && echo.
各キーワードの「重み値」に注目してください。各カテゴリの合計ポイント数をカウントし、最大値を見つけてそのカテゴリに指定されたフォルダにファイルを移動します。また、見つかった単語も表示され、最後にはソートできないファイルがリストされるので、キーワードを追加したり、重み値を微調整したりすることができます。
このサンプルのフォルダとキーワードの数を最小限に抑えました。完全なスクリプトは、6つのフォルダとすべてのキーワード(および成長)と64kのサイズを持っています。
PowerShellで必要な場合は、まず基本コードを自分で実行し、問題があれば*ここに戻り、何が動作していないのか特定の質問をしてください。私が見ることができるところから、既存のバッチコードの主な問題はパフォーマンスです。そうですか? – gravity
私は理解します。そうですね、パフォーマンスです。私はこれが間違ったやり方の主な例だと思う。私が抱えている唯一の実際の問題は特殊文字です。 – bricktop