Sorting files into subdirectories based on keyword scores











up vote
2
down vote

favorite
1












This script sorts files from current directory into known subdirectories. it is built for speed because the keyword database used can be up to 20kb. each line of the database has subdirname,1,keywords?string where the number is how many points this keyword is worth. It then counts these points and puts the file to the subdir with the most points. minimum points for a move is 2. The last line in each database file is missing,0,not appearing in this directory.



dir *.* /a-d >nul 2>nul || exit /b
set "tempfile=%temp%sortables"
set "sourcedir=%~1"
setlocal enabledelayedexpansion

:: set datafile, categories according to where we are
set "categories="
if /i "%cd%"=="d:videos" (
set "datafile=videos"
set "categories=series porno"
)
if /i "%cd%"=="d:videosmovies" (
set "datafile=movies"
set "categories=features psychedelic pornography concerts standup featurettes documentaries"
)
if /i "%cd%"=="d:videosmoviesdocumentaries" (
set "datafile=docu"
set "categories=1-scarcity 2-globalists 3-disinformation 4-agendas 5-abundance"
)
if /i "%cd%"=="d:videosmoviesfeatures" (
set "datafile=films"
set "categories=comedy drama action thriller venture crime horror mystery fantasy science western warfare"
)
if /i "%cd%"=="d:videosseries" (
set "datafile=series"
set "categories=comedy stories1 stories2 reality trippy"
)
if /i "%cd%"=="d:videosseriescomedy" (
set "datafile=comedy"
set "categories=cartoon classic modern reality sketch standup"
)
if /i "%cd%"=="d:videosseriespilots" (
set "datafile=pilots"
set "categories=reality drama comedy scifi fantasy crime mystery action thriller"
)
if /i "%cd%"=="d:videosshorts" (
set "datafile=shorts"
set "categories=psychedelic entertaining music media useful conspiracies"
)
if /i "%cd%"=="d:videosshortsmedia" (
set "datafile=media"
set "categories=trailers games fandom extras facts analysis features"
)
if /i "%cd%"=="d:videosshortsmusic" (
set "datafile=music"
set "categories=bigbeat classical clubbing country electro swing reggae dub experimental geeky metal rap rock synthwave triphop xxx"
)
if not defined categories exit /b
set database=d:systemscripts%datafile%.txt
if not exist "%database%" echo critical error: database %datafile%.txt doesn't exist && exit /b
if defined v%~n0 echo sorting "%cd%"

:: =============================================================================================================================
:: setup sorting categories (do not change anything lightly or without backup after this point)
:: =============================================================================================================================

:: do not remove this echo off or this script will stop working
@echo off

set "sortingcategories="
for %%a in (%categories%) do set "sortingcategories=!sortingcategories!,%%~a"
set "sortingcategories=%sortingcategories: =_%"

:: =============================================================================================================================
:: create tempfile containing lines of: name|sortingcategory|weight
:: =============================================================================================================================
(
for /f "tokens=1,2,*delims=," %%s in (%database%) do (
set "sortingcategory=%%s"
set "sortingcategory=!sortingcategory: =_!"
for /f "delims=" %%a in (
'dir /b /a-d "%sourcedir%*%%u*" 2^>nul'
) do (
echo %%a^|!sortingcategory!^|%%t^|%%s^|%%u
)
)
)>"%tempfile%"
type "%tempfile%" >>d:systemscriptssorter.log

:: =============================================================================================================================
:: reset and call processing for each file in tempfile + dummy (helps counting the last score?)
:: =============================================================================================================================

set "lastname="
for /f "tokens=1,2,3,*delims=|" %%a in ('sort "%tempfile%"') do call :resolve %%b %%c "%%a"
call :resolve dummy 0
:: declare failures
if defined v%~n0 if not "%datafile%"=="videos" if not "%datafile%"=="music" if not "%datafile%"=="media" (
dir "%~1*" /a-d >nul 2>nul && for /f "delims=" %%q in ('dir %1 /b /a-d') do echo unsortable in %datafile% "%%q"
)
exit /b

:resolve
IF "%~3" equ "%lastname%" GOTO accum
:: report and reset accumulators
IF NOT DEFINED lastname GOTO RESET
SET "winner=none"
SET /a maxfound=1
FOR %%v IN (%sortingcategories%) DO (
FOR /f "tokens=1,2delims=$=" %%w IN ('set $%%v') DO IF %%x gtr !maxfound! (SET "winner=%%v"&SET /a maxfound=%%x)
)
if "%winner%"=="none" goto reset
SET "winner=%winner:_= %"
SET "lastname=%lastname:&=and%"
:: this has a problem with different type of dash -
echo "%lastname%" | find /i ".tmp" >nul && exit /b
:: this once overwrote a same-name, much smaller file, wtf?
if "%winner%"=="porno" move "%sourcedir%%lastname%" "d:shame" >nul && echo "d:shame%lastname%"
if not "%winner%"=="porno" move "%sourcedir%%lastname%" "%sourcedir%%winner%" >nul && echo "%sourcedir%%winner%%lastname%"
if "%winner%"=="features" if exist "%sourcedir%%lastname%" move "%sourcedir%%lastname%" "%sourcedir%%winner%" >nul && echo "%sourcedir%%winner%%lastname%"
:: before or after successful filing we could do a surgical dupe check for only that file, rendering the old style obsolete

:RESET
FOR %%v IN (%sortingcategories%) DO SET /a $%%v=0
SET "lastname=%~3"
:accum
SET /a $%1+=%2


It runs nearly perfectly. However, for a file in d:videos to find its way to, say, d:videosshortsmusicelectro, this script will be run three times, once for every subdir. Should this be reworked so it can figure out the final resting place in one go? Would that be feasible? Would it require a single large database file, making it slow again?



I know it's crazy this is done in batch but it's the only language I know. I would love to know about the better ways of doing this.










share|improve this question




























    up vote
    2
    down vote

    favorite
    1












    This script sorts files from current directory into known subdirectories. it is built for speed because the keyword database used can be up to 20kb. each line of the database has subdirname,1,keywords?string where the number is how many points this keyword is worth. It then counts these points and puts the file to the subdir with the most points. minimum points for a move is 2. The last line in each database file is missing,0,not appearing in this directory.



    dir *.* /a-d >nul 2>nul || exit /b
    set "tempfile=%temp%sortables"
    set "sourcedir=%~1"
    setlocal enabledelayedexpansion

    :: set datafile, categories according to where we are
    set "categories="
    if /i "%cd%"=="d:videos" (
    set "datafile=videos"
    set "categories=series porno"
    )
    if /i "%cd%"=="d:videosmovies" (
    set "datafile=movies"
    set "categories=features psychedelic pornography concerts standup featurettes documentaries"
    )
    if /i "%cd%"=="d:videosmoviesdocumentaries" (
    set "datafile=docu"
    set "categories=1-scarcity 2-globalists 3-disinformation 4-agendas 5-abundance"
    )
    if /i "%cd%"=="d:videosmoviesfeatures" (
    set "datafile=films"
    set "categories=comedy drama action thriller venture crime horror mystery fantasy science western warfare"
    )
    if /i "%cd%"=="d:videosseries" (
    set "datafile=series"
    set "categories=comedy stories1 stories2 reality trippy"
    )
    if /i "%cd%"=="d:videosseriescomedy" (
    set "datafile=comedy"
    set "categories=cartoon classic modern reality sketch standup"
    )
    if /i "%cd%"=="d:videosseriespilots" (
    set "datafile=pilots"
    set "categories=reality drama comedy scifi fantasy crime mystery action thriller"
    )
    if /i "%cd%"=="d:videosshorts" (
    set "datafile=shorts"
    set "categories=psychedelic entertaining music media useful conspiracies"
    )
    if /i "%cd%"=="d:videosshortsmedia" (
    set "datafile=media"
    set "categories=trailers games fandom extras facts analysis features"
    )
    if /i "%cd%"=="d:videosshortsmusic" (
    set "datafile=music"
    set "categories=bigbeat classical clubbing country electro swing reggae dub experimental geeky metal rap rock synthwave triphop xxx"
    )
    if not defined categories exit /b
    set database=d:systemscripts%datafile%.txt
    if not exist "%database%" echo critical error: database %datafile%.txt doesn't exist && exit /b
    if defined v%~n0 echo sorting "%cd%"

    :: =============================================================================================================================
    :: setup sorting categories (do not change anything lightly or without backup after this point)
    :: =============================================================================================================================

    :: do not remove this echo off or this script will stop working
    @echo off

    set "sortingcategories="
    for %%a in (%categories%) do set "sortingcategories=!sortingcategories!,%%~a"
    set "sortingcategories=%sortingcategories: =_%"

    :: =============================================================================================================================
    :: create tempfile containing lines of: name|sortingcategory|weight
    :: =============================================================================================================================
    (
    for /f "tokens=1,2,*delims=," %%s in (%database%) do (
    set "sortingcategory=%%s"
    set "sortingcategory=!sortingcategory: =_!"
    for /f "delims=" %%a in (
    'dir /b /a-d "%sourcedir%*%%u*" 2^>nul'
    ) do (
    echo %%a^|!sortingcategory!^|%%t^|%%s^|%%u
    )
    )
    )>"%tempfile%"
    type "%tempfile%" >>d:systemscriptssorter.log

    :: =============================================================================================================================
    :: reset and call processing for each file in tempfile + dummy (helps counting the last score?)
    :: =============================================================================================================================

    set "lastname="
    for /f "tokens=1,2,3,*delims=|" %%a in ('sort "%tempfile%"') do call :resolve %%b %%c "%%a"
    call :resolve dummy 0
    :: declare failures
    if defined v%~n0 if not "%datafile%"=="videos" if not "%datafile%"=="music" if not "%datafile%"=="media" (
    dir "%~1*" /a-d >nul 2>nul && for /f "delims=" %%q in ('dir %1 /b /a-d') do echo unsortable in %datafile% "%%q"
    )
    exit /b

    :resolve
    IF "%~3" equ "%lastname%" GOTO accum
    :: report and reset accumulators
    IF NOT DEFINED lastname GOTO RESET
    SET "winner=none"
    SET /a maxfound=1
    FOR %%v IN (%sortingcategories%) DO (
    FOR /f "tokens=1,2delims=$=" %%w IN ('set $%%v') DO IF %%x gtr !maxfound! (SET "winner=%%v"&SET /a maxfound=%%x)
    )
    if "%winner%"=="none" goto reset
    SET "winner=%winner:_= %"
    SET "lastname=%lastname:&=and%"
    :: this has a problem with different type of dash -
    echo "%lastname%" | find /i ".tmp" >nul && exit /b
    :: this once overwrote a same-name, much smaller file, wtf?
    if "%winner%"=="porno" move "%sourcedir%%lastname%" "d:shame" >nul && echo "d:shame%lastname%"
    if not "%winner%"=="porno" move "%sourcedir%%lastname%" "%sourcedir%%winner%" >nul && echo "%sourcedir%%winner%%lastname%"
    if "%winner%"=="features" if exist "%sourcedir%%lastname%" move "%sourcedir%%lastname%" "%sourcedir%%winner%" >nul && echo "%sourcedir%%winner%%lastname%"
    :: before or after successful filing we could do a surgical dupe check for only that file, rendering the old style obsolete

    :RESET
    FOR %%v IN (%sortingcategories%) DO SET /a $%%v=0
    SET "lastname=%~3"
    :accum
    SET /a $%1+=%2


    It runs nearly perfectly. However, for a file in d:videos to find its way to, say, d:videosshortsmusicelectro, this script will be run three times, once for every subdir. Should this be reworked so it can figure out the final resting place in one go? Would that be feasible? Would it require a single large database file, making it slow again?



    I know it's crazy this is done in batch but it's the only language I know. I would love to know about the better ways of doing this.










    share|improve this question


























      up vote
      2
      down vote

      favorite
      1









      up vote
      2
      down vote

      favorite
      1






      1





      This script sorts files from current directory into known subdirectories. it is built for speed because the keyword database used can be up to 20kb. each line of the database has subdirname,1,keywords?string where the number is how many points this keyword is worth. It then counts these points and puts the file to the subdir with the most points. minimum points for a move is 2. The last line in each database file is missing,0,not appearing in this directory.



      dir *.* /a-d >nul 2>nul || exit /b
      set "tempfile=%temp%sortables"
      set "sourcedir=%~1"
      setlocal enabledelayedexpansion

      :: set datafile, categories according to where we are
      set "categories="
      if /i "%cd%"=="d:videos" (
      set "datafile=videos"
      set "categories=series porno"
      )
      if /i "%cd%"=="d:videosmovies" (
      set "datafile=movies"
      set "categories=features psychedelic pornography concerts standup featurettes documentaries"
      )
      if /i "%cd%"=="d:videosmoviesdocumentaries" (
      set "datafile=docu"
      set "categories=1-scarcity 2-globalists 3-disinformation 4-agendas 5-abundance"
      )
      if /i "%cd%"=="d:videosmoviesfeatures" (
      set "datafile=films"
      set "categories=comedy drama action thriller venture crime horror mystery fantasy science western warfare"
      )
      if /i "%cd%"=="d:videosseries" (
      set "datafile=series"
      set "categories=comedy stories1 stories2 reality trippy"
      )
      if /i "%cd%"=="d:videosseriescomedy" (
      set "datafile=comedy"
      set "categories=cartoon classic modern reality sketch standup"
      )
      if /i "%cd%"=="d:videosseriespilots" (
      set "datafile=pilots"
      set "categories=reality drama comedy scifi fantasy crime mystery action thriller"
      )
      if /i "%cd%"=="d:videosshorts" (
      set "datafile=shorts"
      set "categories=psychedelic entertaining music media useful conspiracies"
      )
      if /i "%cd%"=="d:videosshortsmedia" (
      set "datafile=media"
      set "categories=trailers games fandom extras facts analysis features"
      )
      if /i "%cd%"=="d:videosshortsmusic" (
      set "datafile=music"
      set "categories=bigbeat classical clubbing country electro swing reggae dub experimental geeky metal rap rock synthwave triphop xxx"
      )
      if not defined categories exit /b
      set database=d:systemscripts%datafile%.txt
      if not exist "%database%" echo critical error: database %datafile%.txt doesn't exist && exit /b
      if defined v%~n0 echo sorting "%cd%"

      :: =============================================================================================================================
      :: setup sorting categories (do not change anything lightly or without backup after this point)
      :: =============================================================================================================================

      :: do not remove this echo off or this script will stop working
      @echo off

      set "sortingcategories="
      for %%a in (%categories%) do set "sortingcategories=!sortingcategories!,%%~a"
      set "sortingcategories=%sortingcategories: =_%"

      :: =============================================================================================================================
      :: create tempfile containing lines of: name|sortingcategory|weight
      :: =============================================================================================================================
      (
      for /f "tokens=1,2,*delims=," %%s in (%database%) do (
      set "sortingcategory=%%s"
      set "sortingcategory=!sortingcategory: =_!"
      for /f "delims=" %%a in (
      'dir /b /a-d "%sourcedir%*%%u*" 2^>nul'
      ) do (
      echo %%a^|!sortingcategory!^|%%t^|%%s^|%%u
      )
      )
      )>"%tempfile%"
      type "%tempfile%" >>d:systemscriptssorter.log

      :: =============================================================================================================================
      :: reset and call processing for each file in tempfile + dummy (helps counting the last score?)
      :: =============================================================================================================================

      set "lastname="
      for /f "tokens=1,2,3,*delims=|" %%a in ('sort "%tempfile%"') do call :resolve %%b %%c "%%a"
      call :resolve dummy 0
      :: declare failures
      if defined v%~n0 if not "%datafile%"=="videos" if not "%datafile%"=="music" if not "%datafile%"=="media" (
      dir "%~1*" /a-d >nul 2>nul && for /f "delims=" %%q in ('dir %1 /b /a-d') do echo unsortable in %datafile% "%%q"
      )
      exit /b

      :resolve
      IF "%~3" equ "%lastname%" GOTO accum
      :: report and reset accumulators
      IF NOT DEFINED lastname GOTO RESET
      SET "winner=none"
      SET /a maxfound=1
      FOR %%v IN (%sortingcategories%) DO (
      FOR /f "tokens=1,2delims=$=" %%w IN ('set $%%v') DO IF %%x gtr !maxfound! (SET "winner=%%v"&SET /a maxfound=%%x)
      )
      if "%winner%"=="none" goto reset
      SET "winner=%winner:_= %"
      SET "lastname=%lastname:&=and%"
      :: this has a problem with different type of dash -
      echo "%lastname%" | find /i ".tmp" >nul && exit /b
      :: this once overwrote a same-name, much smaller file, wtf?
      if "%winner%"=="porno" move "%sourcedir%%lastname%" "d:shame" >nul && echo "d:shame%lastname%"
      if not "%winner%"=="porno" move "%sourcedir%%lastname%" "%sourcedir%%winner%" >nul && echo "%sourcedir%%winner%%lastname%"
      if "%winner%"=="features" if exist "%sourcedir%%lastname%" move "%sourcedir%%lastname%" "%sourcedir%%winner%" >nul && echo "%sourcedir%%winner%%lastname%"
      :: before or after successful filing we could do a surgical dupe check for only that file, rendering the old style obsolete

      :RESET
      FOR %%v IN (%sortingcategories%) DO SET /a $%%v=0
      SET "lastname=%~3"
      :accum
      SET /a $%1+=%2


      It runs nearly perfectly. However, for a file in d:videos to find its way to, say, d:videosshortsmusicelectro, this script will be run three times, once for every subdir. Should this be reworked so it can figure out the final resting place in one go? Would that be feasible? Would it require a single large database file, making it slow again?



      I know it's crazy this is done in batch but it's the only language I know. I would love to know about the better ways of doing this.










      share|improve this question















      This script sorts files from current directory into known subdirectories. it is built for speed because the keyword database used can be up to 20kb. each line of the database has subdirname,1,keywords?string where the number is how many points this keyword is worth. It then counts these points and puts the file to the subdir with the most points. minimum points for a move is 2. The last line in each database file is missing,0,not appearing in this directory.



      dir *.* /a-d >nul 2>nul || exit /b
      set "tempfile=%temp%sortables"
      set "sourcedir=%~1"
      setlocal enabledelayedexpansion

      :: set datafile, categories according to where we are
      set "categories="
      if /i "%cd%"=="d:videos" (
      set "datafile=videos"
      set "categories=series porno"
      )
      if /i "%cd%"=="d:videosmovies" (
      set "datafile=movies"
      set "categories=features psychedelic pornography concerts standup featurettes documentaries"
      )
      if /i "%cd%"=="d:videosmoviesdocumentaries" (
      set "datafile=docu"
      set "categories=1-scarcity 2-globalists 3-disinformation 4-agendas 5-abundance"
      )
      if /i "%cd%"=="d:videosmoviesfeatures" (
      set "datafile=films"
      set "categories=comedy drama action thriller venture crime horror mystery fantasy science western warfare"
      )
      if /i "%cd%"=="d:videosseries" (
      set "datafile=series"
      set "categories=comedy stories1 stories2 reality trippy"
      )
      if /i "%cd%"=="d:videosseriescomedy" (
      set "datafile=comedy"
      set "categories=cartoon classic modern reality sketch standup"
      )
      if /i "%cd%"=="d:videosseriespilots" (
      set "datafile=pilots"
      set "categories=reality drama comedy scifi fantasy crime mystery action thriller"
      )
      if /i "%cd%"=="d:videosshorts" (
      set "datafile=shorts"
      set "categories=psychedelic entertaining music media useful conspiracies"
      )
      if /i "%cd%"=="d:videosshortsmedia" (
      set "datafile=media"
      set "categories=trailers games fandom extras facts analysis features"
      )
      if /i "%cd%"=="d:videosshortsmusic" (
      set "datafile=music"
      set "categories=bigbeat classical clubbing country electro swing reggae dub experimental geeky metal rap rock synthwave triphop xxx"
      )
      if not defined categories exit /b
      set database=d:systemscripts%datafile%.txt
      if not exist "%database%" echo critical error: database %datafile%.txt doesn't exist && exit /b
      if defined v%~n0 echo sorting "%cd%"

      :: =============================================================================================================================
      :: setup sorting categories (do not change anything lightly or without backup after this point)
      :: =============================================================================================================================

      :: do not remove this echo off or this script will stop working
      @echo off

      set "sortingcategories="
      for %%a in (%categories%) do set "sortingcategories=!sortingcategories!,%%~a"
      set "sortingcategories=%sortingcategories: =_%"

      :: =============================================================================================================================
      :: create tempfile containing lines of: name|sortingcategory|weight
      :: =============================================================================================================================
      (
      for /f "tokens=1,2,*delims=," %%s in (%database%) do (
      set "sortingcategory=%%s"
      set "sortingcategory=!sortingcategory: =_!"
      for /f "delims=" %%a in (
      'dir /b /a-d "%sourcedir%*%%u*" 2^>nul'
      ) do (
      echo %%a^|!sortingcategory!^|%%t^|%%s^|%%u
      )
      )
      )>"%tempfile%"
      type "%tempfile%" >>d:systemscriptssorter.log

      :: =============================================================================================================================
      :: reset and call processing for each file in tempfile + dummy (helps counting the last score?)
      :: =============================================================================================================================

      set "lastname="
      for /f "tokens=1,2,3,*delims=|" %%a in ('sort "%tempfile%"') do call :resolve %%b %%c "%%a"
      call :resolve dummy 0
      :: declare failures
      if defined v%~n0 if not "%datafile%"=="videos" if not "%datafile%"=="music" if not "%datafile%"=="media" (
      dir "%~1*" /a-d >nul 2>nul && for /f "delims=" %%q in ('dir %1 /b /a-d') do echo unsortable in %datafile% "%%q"
      )
      exit /b

      :resolve
      IF "%~3" equ "%lastname%" GOTO accum
      :: report and reset accumulators
      IF NOT DEFINED lastname GOTO RESET
      SET "winner=none"
      SET /a maxfound=1
      FOR %%v IN (%sortingcategories%) DO (
      FOR /f "tokens=1,2delims=$=" %%w IN ('set $%%v') DO IF %%x gtr !maxfound! (SET "winner=%%v"&SET /a maxfound=%%x)
      )
      if "%winner%"=="none" goto reset
      SET "winner=%winner:_= %"
      SET "lastname=%lastname:&=and%"
      :: this has a problem with different type of dash -
      echo "%lastname%" | find /i ".tmp" >nul && exit /b
      :: this once overwrote a same-name, much smaller file, wtf?
      if "%winner%"=="porno" move "%sourcedir%%lastname%" "d:shame" >nul && echo "d:shame%lastname%"
      if not "%winner%"=="porno" move "%sourcedir%%lastname%" "%sourcedir%%winner%" >nul && echo "%sourcedir%%winner%%lastname%"
      if "%winner%"=="features" if exist "%sourcedir%%lastname%" move "%sourcedir%%lastname%" "%sourcedir%%winner%" >nul && echo "%sourcedir%%winner%%lastname%"
      :: before or after successful filing we could do a surgical dupe check for only that file, rendering the old style obsolete

      :RESET
      FOR %%v IN (%sortingcategories%) DO SET /a $%%v=0
      SET "lastname=%~3"
      :accum
      SET /a $%1+=%2


      It runs nearly perfectly. However, for a file in d:videos to find its way to, say, d:videosshortsmusicelectro, this script will be run three times, once for every subdir. Should this be reworked so it can figure out the final resting place in one go? Would that be feasible? Would it require a single large database file, making it slow again?



      I know it's crazy this is done in batch but it's the only language I know. I would love to know about the better ways of doing this.







      performance csv file-system batch






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 1 at 15:15









      200_success

      128k15149412




      128k15149412










      asked Sep 1 at 13:58









      bricktop

      265




      265






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Maybe the following wrapper script could help:



          @ECHO OFF
          SETLOCAL EnableExtensions
          set "_OrigScript=D:batCodeReview202927.bat" # change to match your terms
          CD /D "d:videos"
          FOR /D /r %%G in (.) DO (
          pushd %%~fG
          call "%_OrigScript%"
          popd
          )


          Explanation (required reading):





          • FOR /D Conditionally perform a command on several Directories/Folders.


          • PUSHD Change the current directory/folder and store the previous folder/path for use by the POPD command.


          • POPD Change directory back to the path/folder most recently stored by the PUSHD command.


          • CALL Call one batch program from another, or call a subroutine.






          share|improve this answer





















            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "196"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f202927%2fsorting-files-into-subdirectories-based-on-keyword-scores%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Maybe the following wrapper script could help:



            @ECHO OFF
            SETLOCAL EnableExtensions
            set "_OrigScript=D:batCodeReview202927.bat" # change to match your terms
            CD /D "d:videos"
            FOR /D /r %%G in (.) DO (
            pushd %%~fG
            call "%_OrigScript%"
            popd
            )


            Explanation (required reading):





            • FOR /D Conditionally perform a command on several Directories/Folders.


            • PUSHD Change the current directory/folder and store the previous folder/path for use by the POPD command.


            • POPD Change directory back to the path/folder most recently stored by the PUSHD command.


            • CALL Call one batch program from another, or call a subroutine.






            share|improve this answer

























              up vote
              0
              down vote













              Maybe the following wrapper script could help:



              @ECHO OFF
              SETLOCAL EnableExtensions
              set "_OrigScript=D:batCodeReview202927.bat" # change to match your terms
              CD /D "d:videos"
              FOR /D /r %%G in (.) DO (
              pushd %%~fG
              call "%_OrigScript%"
              popd
              )


              Explanation (required reading):





              • FOR /D Conditionally perform a command on several Directories/Folders.


              • PUSHD Change the current directory/folder and store the previous folder/path for use by the POPD command.


              • POPD Change directory back to the path/folder most recently stored by the PUSHD command.


              • CALL Call one batch program from another, or call a subroutine.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Maybe the following wrapper script could help:



                @ECHO OFF
                SETLOCAL EnableExtensions
                set "_OrigScript=D:batCodeReview202927.bat" # change to match your terms
                CD /D "d:videos"
                FOR /D /r %%G in (.) DO (
                pushd %%~fG
                call "%_OrigScript%"
                popd
                )


                Explanation (required reading):





                • FOR /D Conditionally perform a command on several Directories/Folders.


                • PUSHD Change the current directory/folder and store the previous folder/path for use by the POPD command.


                • POPD Change directory back to the path/folder most recently stored by the PUSHD command.


                • CALL Call one batch program from another, or call a subroutine.






                share|improve this answer












                Maybe the following wrapper script could help:



                @ECHO OFF
                SETLOCAL EnableExtensions
                set "_OrigScript=D:batCodeReview202927.bat" # change to match your terms
                CD /D "d:videos"
                FOR /D /r %%G in (.) DO (
                pushd %%~fG
                call "%_OrigScript%"
                popd
                )


                Explanation (required reading):





                • FOR /D Conditionally perform a command on several Directories/Folders.


                • PUSHD Change the current directory/folder and store the previous folder/path for use by the POPD command.


                • POPD Change directory back to the path/folder most recently stored by the PUSHD command.


                • CALL Call one batch program from another, or call a subroutine.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 12 hours ago









                JosefZ

                22629




                22629






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Code Review Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f202927%2fsorting-files-into-subdirectories-based-on-keyword-scores%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Quarter-circle Tiles

                    build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

                    Mont Emei