⬆️ ⬇️

And the old BAT-nick warms the soul

Sometimes there are situations when you want to automate a small task a little, but there is no favorite tool at hand. Or just laziness to code something in your favorite “ultra-modern” IDE for the petty task, I want to somehow make it easier, in more systemic and down-to-earth ways. At least that's what I have :)



And then for some reason, the good old bat immediately comes to my mind (we don’t consider Linux users, everything is much simpler there).



How nice it sometimes happens when what you learned in school (and the institute) even then can somehow be used now !!!

Let even for such a trivial task as the formation of a playlist of the desired directory.

')

Although even this task appeared for a reason. Sometime back in 2004, leafing through the help of the then fashionable Light Alloy media player (and I still have it on it until now), I met an elementary shemk of a receiver for the remote control. Even my modest knowledge in electronics could not resist curiosity and such a simple scheme. Conceived - done. And let the clumsy, but still working receiver was welded. It remains to be easy - to learn how to use it :) After some searching on the Internet, the choice was on Girder 3.10, after which the latter was successfully set to use the main programs (winamp, la, far, explorer) and everything became absolutely good.

But not for nothing they say: the best is the enemy of the good. And with the advent of a larger screw, a local grid and a fast (relatively) Internet, the choice of new music and movies has become harder to do while lying on the couch - and you want it.



The solution, taking into account the ability of Girder-a to create its own OSD menu, was simple - all that was missing was the “command” to create the list of files in the directory where I was throwing new films.

Here it is time to remember about bat. The first option was sketched in a few minutes, after a detailed study of the dir command. But then I wanted more - the choice of video files only, without descriptions and incomplete downloads, the choice of not the entire directory, but only parts of files, etc.

Fortunately, opening the help for batch files, I saw that their capabilities in XP had grown in comparison with the 98th, which was very nice.



Well, here's the result:

_vnew.bat (lies in the folder specified in the PATH variable)

@ECHO OFF



REM

REM ( )

setlocal enabledelayedexpansion



REM

set ftypes=*.AVI *.ASF *.DAT *.DIVX *.M*V *.MP4 *.MPE *.MP*G *.OGM *.VOB *.WM*



REM

set TFILE=



REM

set TDIR=%cd%



set EXTLIST=0



REM

if NOT ~%1~==~~ set TDIR=%1



REM

REM ( - )

if /i ~%2~==~/file~ set TFILE=%3& shift 2& shift 2

if ~%TFILE%~==~~ set TFILE=%cd%\_vnew.lap



REM ( )

if '%2'=='' set FT=%ftypes%



echo %TDIR% %FT% %TFILE%. Ctrl+C

rem pause



REM

del %TFILE% >nul



REM Windows

chcp 1251



REM ( ),

REM

if ~%2~==~~ goto nexttype



REM ,

set EXTLIST=1



REM ( ) ,

REM -

:np

rem echo --%2-- & pause

if not ~%2~==~~ set FN=%2& shift 2& goto formlist

goto end



REM ""

:nexttype

for /F "tokens=1*" %%F in ("%FT%") do set FN=%%F & set FT=%%G



REM

:formlist



REM

for %%N in (!TDIR!) do set TDIR=%%~N

for %%N in (!FN!) do set FN=%%~N



REM "dir /ad /s /b +"

REM

rem dir /ad /s /b "!TDIR!\!FN!" >>%TFILE%



REM , , .

FOR /F "usebackq DELIMS=*" %%X IN (`dir /ad /s /b "!TDIR!\!FN!"`) DO echo %%X >>%TFILE%

REM , , "",

REM , GOM-

REM FOR /F "usebackq DELIMS=*" %%X IN (`dir /ad /s /b "!TDIR!\!FN!"`) DO echo ^<entry^>^<title^>%%X^</title^>^/^>^</entry^> >>%TFILE%



REM ,

if %EXTLIST%==1 goto np

if not "%FT%"=="" goto nexttype



REM ( )

REM

:end

rem sort %TFILE% /O %TFILE%

chcp 866

if exist %TFILE% start %TFILE%





Call examples:

_vnew.bat M:\Media\Mult\New



_vnew.bat "E:\Video\Mult\Ussr\" /file=e:\video\rr.lap new1 zerkalce.avi " .avi"



_vnew.bat "E:\Video\Mult\Ussr\" /file=e:\video\rr.lap *.avi





Now this script (with different parameters) is the most called from both the console and the desktop (a trifle chooses to look at a couple of thousand cartoons), and the head doesn’t hurt that something was added, deleted or moved in a folder.

And you can always change it without any problems.



In general, who will come in handy - I will only be very happy :)



PS Special thanks to viperet for the invitation :)

PPS in addition, the very “picking” of the technology of youth brings a lot of pleasure, if this is relevant - so if you have a suitable task, do not miss the chance;)



UPD: corrected the script a little bit (I edited the rules once in the browser - it was sealed up :()

Source: https://habr.com/ru/post/76828/



All Articles