# How to check if AviSynth is installed (from a Windows batch file)

1. I've written a batch file that successfully creates AVS files (based on the input files that were drag-dropped onto the batch) and encodes them using FFMPEG; however, I would like to be able to check if the user has installed AviSynth, and do so from within the batch file.

1) What is the best way to do this?

On my computer I could do something like IF EXIST "C:\Program Files (x86)\AviSynth 2.5" but that is far from foolproof and will only work for version 2.5, and the folder (and even files within) might exist even if AviSynth has been installed.

2) While I'm asking, if I want to include a whole (large) AVS file in a batch file, so that the batch file will write it into an AVS, I know I need to escape the content (especially the brackets) and use the likes of ECHO or TYPE to put the text line by line into a .avs file, but is there an easy way to automatically escape all the lines? Ideally a wee program (or batch file, indeed) that would also add the ECHO or TYPE commands for each line. I don't even know which characters need to be escaped.

Thanks!
2. You can search for avisynth.dll in %SYSTEMROOT%\System32\ or %SYSTEMROOT%\SysWOW64\. It's still possible the dll is there but AviSynth isn't registered.
3. 2)
some signs like "&" if you have functions in script, then must be "^&", but there should be no problem using ECHO , common characters like = ( ) are ok after ECHO,
this is not a problem really because when something needs to be escaped you just read that script that batch created and you can see exactly at what point, character, it went wrong
4. Thanks guys.

I had searched for avisynth.dll in %SYSTEMROOT%\System32\ but couldn't find it. Turns out it's in %SYSTEMROOT%\SysWOW64\ on my PC, so that's just fine Hopefully those are the only two locations avisynth.dll could exist.

Regarding escaping the AVS, I found this frikkin' awesome way of including a web page (actually an HTML application) within a batch file without escaping it. I should be able to easily modify it to use an AVS file:

(My AVS is 18kB at the moment and getting bigger by the day, so it's useful to not have to escape it problem by problem!)

The method above uses the line:

type %0 | find " " | find /v "Not Me!" > %TEMP%\UserIn.hta

It copies all the lines of the current batch file that have " " (four consecutive spaces) anywhere in the line, but not the phrase "Not Me!". This means each line of code can have four spaces put at the start and it will be picked up! Genius solution.
5. Originally Posted by as264
I had searched for avisynth.dll in %SYSTEMROOT%\System32\ but couldn't find it. Turns out it's in %SYSTEMROOT%\SysWOW64\ on my PC, so that's just fine Hopefully those are the only two locations avisynth.dll could exist.
Under 32 bit Windows avisynth.dll will be in system32. Under 64 bit windows 32 bit avisynth.dll will be in syswow64, 64 bit avisynth.dll will be system32 (no, those are not typos). Be aware that 32 bit programs cannot access 64 bit AviSynth, and vice versa.
Code:
type %0 | find "    " | find /v "Not Me!" > %TEMP%\UserIn.hta
those four spaces come out alright wrapped in code tag, "Go advanced" button before posting.
7. I would just redirect TYPE (of another file) to the output file:

Code:
TYPE prototype.avs >new.avs
If I need to append anything I just use >>. Here's a batch file that builds a simple AVS script:

Code:
echo import("C:\Program Files (x86)\AviSynth 2.5\plugins\Null.avs") > "%~d1%~p1%~n1.avs"
echo Mpeg2Source("%~d1%~p1%~n1%~x1", CPU=2, Info=3) >> "%~d1%~p1%~n1.avs"
echo TFM(d2v="%~d1%~p1%~n1%~x1") >> "%~d1%~p1%~n1.avs"
echo TDecimate() >> "%~d1%~p1%~n1.avs"
That lives in my SendTo folder as AVS-Mpeg2Source.bat. So I can right click on a d2v file and select SendTo -> AVS-Mpeg2Source.bat. Right clicking on a file called filename.d2v results in a file called filename.avs in the same folder. The avs file contains:

Code:
import("C:\Program Files (x86)\AviSynth 2.5\plugins\Null.avs")
Mpeg2Source("full\path\to\filename.d2v", CPU=2, Info=3)
TFM(d2v="full\path\to\filename.d2v")
TDecimate()
8. @jagabo : yes, I'm using TYPE and appending with >> at the moment. It's just for giving someone else the .bat to use; it would be convenient for everything (including the .avs) to be within one file. They're totally non-tech-savvy so in reality I'm going to probably have to give them AviSynth, ffmpeg.exe, a couple of AviSynth plugins, some images that get used by the avs, the big AVS and the batch file, all in one file.

I'm going to give "bat2exe.exe" a go to put everything in one .exe that automatically passes on any arguments to the .bat file within. Hopefully the .bat and .avs will be able to access all the files within; or at least be able to copy the files into a temporary directory each time and delete them after. If that doesn't work I guess I'll have to use a .zip file with everything in one folder at least, or is there a better solution? I want to have just one file onto which they can just drag-drop as many video files as they like and it will process and encode them all.

ps - I think "%~d1%~p1%~n1%~x1" can be abbreviated to "%~dpnx1" - unless there is some advantage to separating all the parts?

pps - now I see the Go Advanced option.
9. Originally Posted by as264
ps - I think "%~d1%~p1%~n1%~x1" can be abbreviated to "%~dpnx1"
Thanks, I didn't know that.
10. Originally Posted by as264
"%~d1%~p1%~n1%~x1" can be abbreviated to "%~dpnx1" - unless there is some advantage to separating all the parts?
it is the same, bottom line is avoiding %1, because Windows puts quotes around file name if there is a space character in the path, which can bring double quotes around file and things do not work,

you can use even %whatever_file% into avisynth and branch script if avs is inside the same BAT, that is the advantage,
another advantage to have delivered in zip, folder structure, that you can have included some tool folder , with another programs in it or folders, plugins etc..., then you can use "%~dp0" that returns path of BAT file, wherever it is in PC, you can get something like this:
Code:
:: user can set temp folder anywhere like: set path_temp=E:\temp and it will create temp on E:\
:: today folks use SSD and such, you do not want much activity on SSD, so any temp files
:: in script should go to the temp folder
:: temp folder could be simply deleted at the end

set path_temp=%~dp0temp
MD "%path_temp%"
SET input_name=%~d1%~p1%~n1%~x1
SET name=%~n1
SET plugin_folder=%~dp0tools\plugins
SET DGDecode.dll=%~dp0tools\dgindex\DGDecode.dll
.
.
.

:end_avs_script