trof Posted November 6, 2016 Share Posted November 6, 2016 (edited) Hi, I'd like to use Windows SendTo context menu entry to create an avisynth script for every selected file. I created this script that works when I select only one file #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> Example() Func Example() ; Create a constant variable in Local scope of the filepath that will be read/written to. Local Const $sFilePath = $CmdLineRaw & ".avs" ; Create a temporary file to write data to. If Not FileWrite($sFilePath, "LoadPlugin(" & '"' & "C:\Program Files (x86)\AviSynth+\plugins+\avssr.dll" & '"' & ")" & @CRLF) Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.") Return False EndIf Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file2.") Return False EndIf FileWriteLine($hFileOpen, "# loading source: " & $CmdLineRaw) FileWriteLine($hFileOpen, "FFVideoSource(" & '"' & $CmdLineRaw & '"' & ")") FileWriteLine($hFileOpen, "dispWidth = 1920") FileWriteLine($hFileOpen, "dispHeight = 1080") FileWriteLine($hFileOpen, "mWidth = float(last.width)") FileWriteLine($hFileOpen, "mHeight = float(last.height)") FileWriteLine($hFileOpen, "ratio = (mWidth/mHeight)") FileWriteLine($hFileOpen, "newHeight= round(dispWidth/ratio)/2)*2") FileWriteLine($hFileOpen, "newHeight > dispHeight ? Eval(" & '"""') FileWriteLine($hFileOpen, "newHeight=dispHeight") FileWriteLine($hFileOpen, "newWidth=round((newHeight*ratio)/2)*2") FileWriteLine($hFileOpen, '"""' & ") : Eval(" & '"""') FileWriteLine($hFileOpen, "newWidth=dispWidth") FileWriteLine($hFileOpen, '"""' & ")") FileWriteLine($hFileOpen, "SR(newWidth,newHeight)") EndFunc But I'd like to use the SendTo function on multiple files I have this error message when I select multiple files Edited November 6, 2016 by trof Link to comment Share on other sites More sharing options...
j0kky Posted November 6, 2016 Share Posted November 6, 2016 From the help: Quote So if you were to run your script directly using AutoIt3.exe: AutoIt3.exe myScript.au3 param1 "This is a string parameter" 99 $CmdLine[0] ; This contains 3 parameters.$CmdLine[1] ; This contains param1 and not myScript.au3 as this is ignored when running non-compiled.$CmdLine[2] ; This contains This is a string parameter.$CmdLine[3] ; This contains 99.$CmdLineRaw ; This contains myScript.au3 param1 "This is a string parameter" 99. I think your $sFilePath is not a valid path. Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
trof Posted November 6, 2016 Author Share Posted November 6, 2016 3 minutes ago, j0kky said: I think your $sFilePath is not a valid path. It works when I send only one file to SendTo menu Link to comment Share on other sites More sharing options...
j0kky Posted November 6, 2016 Share Posted November 6, 2016 (edited) try to add: Local Const $sFilePath = $CmdLineRaw & ".avs" ConsoleWrite($sFilePath & @CRLF) and post here the console output when you select one file and when you select more than one file... Edited November 6, 2016 by j0kky Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
trof Posted November 6, 2016 Author Share Posted November 6, 2016 Sorry for this stupid question, but where I can find the console output. I have to compile the script to use SendTo menu Link to comment Share on other sites More sharing options...
j0kky Posted November 6, 2016 Share Posted November 6, 2016 (edited) sorry, you can't retrieve easily console output when compiled, use instead: Local Const $sFilePath = $CmdLineRaw & ".avs" FileWrite(FileOpen(@DesktopDir & "/log.txt", 2), $sFilePath) ShellExecute(@DesktopDir & "/log.txt") Edited November 6, 2016 by j0kky Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
trof Posted November 6, 2016 Author Share Posted November 6, 2016 Log with one file selected: F:\Gloria\3\S3020123.AVI.avs Log with 3 files selected: F:\Gloria\3\S3020125.AVI F:\Gloria\3\S3020123.AVI F:\Gloria\3\S3020124.AVI.avs Link to comment Share on other sites More sharing options...
j0kky Posted November 6, 2016 Share Posted November 6, 2016 (edited) I admit it takes me some time to understand the problem, but here it is: when you select just one file, FileWrite takes $sFilePath as a complete filePATH and everything works well. But when you select multiple files, Filewrite takes $sFilePath as a fileNAME and it tries to create a new file in the folder where the compiled script is executed, using each character you provide through $CmdLineRaw... But it contains "\" character too which is forbidden in filenames, so the function fails. Edited November 6, 2016 by j0kky Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
trof Posted November 6, 2016 Author Share Posted November 6, 2016 Ok, is it possible to modify the script to make it working well? Link to comment Share on other sites More sharing options...
j0kky Posted November 6, 2016 Share Posted November 6, 2016 (edited) Yes, you can do it through regular expressions, for example this line of code remove the major part of forbidden character from the filename: $sFilePath = StringRegExpReplace($CmdLineRaw & ".avs", '[\\"/:|]', "") But there are some advices you should pay attention: - the maximum lenght of a FilePath + FileName should be 255 characters - if you select a file which is in a folder where you don't have the right to create a file, it fails Edited November 6, 2016 by j0kky Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
trof Posted November 6, 2016 Author Share Posted November 6, 2016 5 hours ago, j0kky said: Yes, you can do it through regular expressions, for example this line of code remove the major part of forbidden character from the filename: $sFilePath = StringRegExpReplace($CmdLineRaw & ".avs", '[\\"/:|]', "") But there are some advices you should pay attention: - the maximum lenght of a FilePath + FileName should be 255 characters - if you select a file which is in a folder where you don't have the right to create a file, it fails I have problems with that script. It is created an only file with the name of the selected files and the name of the working folder. Eg. The selected files are S3020125.AVI S3020125.AVI.asf S3020124.AVI The working folder is F:\Gloria\3 the result of the script is the creation of one file named "FGloria3S3020125.AVI FGloria3S3020125.AVI.asf FGloria3S3020124.AVI.avs" Link to comment Share on other sites More sharing options...
j0kky Posted November 6, 2016 Share Posted November 6, 2016 (edited) I know it... Isn't it the behavior you wanted? EDIT: If you want to have an .avs file per selected file, you just have to include the script in a loop: For $i = 1 To $CmdLine[0] $sFilePath = $CmdLine[$i] & ".avs" If Not FileWrite($sFilePath, "LoadPlugin(" & '"' & "C:\Program Files (x86)\AviSynth+\plugins+\avssr.dll" & '"' & ")" & @CRLF) Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.") Return False EndIf ;the rest of the script Next Edited November 6, 2016 by j0kky trof 1 Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
trof Posted November 7, 2016 Author Share Posted November 7, 2016 (edited) Thanks, that's what I want. One last thing. I, also, created this script expandcollapse popup#include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <File.au3> Example2() Func Example2() Local $aFileavi = _FileListToArray(@ScriptDir & "\", "*.avi") Local $path = @ScriptDir For $i = 1 To $aFileavi[0] Local $sFilePath = $aFileavi[$i] & ".avs" ConsoleWrite($sFilePath & @CRLF) FileWrite(FileOpen(@DesktopDir & "/log.txt", 2), $sFilePath) ShellExecuteWait(@DesktopDir & "/log.txt") ; Create a temporary file to write data to. If Not FileWrite($sFilePath, "LoadPlugin(" & '"' & "C:\Program Files (x86)\AviSynth+\plugins+\avssr.dll" & '"' & ")" & @CRLF) Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.") Return False EndIf Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file2.") Return False EndIf FileWriteLine($hFileOpen, "# loading source: " & $aFileavi[$i]) FileWriteLine($hFileOpen, "FFVideoSource(" & '"' & $aFileavi[$i] & '"' & ")") FileWriteLine($hFileOpen, "dispWidth = 1920") FileWriteLine($hFileOpen, "dispHeight = 1080") FileWriteLine($hFileOpen, "mWidth = float(last.width)") FileWriteLine($hFileOpen, "mHeight = float(last.height)") FileWriteLine($hFileOpen, "ratio = (mWidth/mHeight)") FileWriteLine($hFileOpen, "newHeight= round(dispWidth/ratio)/2)*2") FileWriteLine($hFileOpen, "newHeight > dispHeight ? Eval(" & '"""') FileWriteLine($hFileOpen, "newHeight=dispHeight") FileWriteLine($hFileOpen, "newWidth=round((newHeight*ratio)/2)*2") FileWriteLine($hFileOpen, '"""' & ") : Eval(" & '"""') FileWriteLine($hFileOpen, "newWidth=dispWidth") FileWriteLine($hFileOpen, '"""' & ")") FileWriteLine($hFileOpen, "SR(newWidth,newHeight)") Next EndFunc ;==>Example It works well on avi files, so I tried to use it even with other video extensions. expandcollapse popup#include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <File.au3> Example() Func Example() Local $aArray[16] $aArray[0] = ".asf" $aArray[1] = ".avi" $aArray[2] = ".divx" $aArray[3] = ".flv" $aArray[4] = ".mkv" $aArray[5] = ".mov" $aArray[6] = ".mp4" $aArray[7] = ".mpe" $aArray[8] = ".mpeg" $aArray[9] = ".mpg" $aArray[10] = ".ts" $aArray[11] = ".vob" $aArray[12] = ".wmv" $aArray[13] = ".xvid" $aArray[14] = ".h264" $aArray[15] = ".h265" For $vElement In $aArray Local $aFileList = _FileListToArray(@ScriptDir & "\", $vElement) Local $path = @ScriptDir For $i = 1 To $aFileList[0] Local $sFilePath = $aFileList[$i] & ".avs" ConsoleWrite($sFilePath & @CRLF) FileWrite(FileOpen(@DesktopDir & "/log.txt", 2), $sFilePath) ShellExecuteWait(@DesktopDir & "/log.txt") ; Create a temporary file to write data to. If Not FileWrite($sFilePath, "LoadPlugin(" & '"' & "C:\Program Files (x86)\AviSynth+\plugins+\avssr.dll" & '"' & ")" & @CRLF) Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.") Return False EndIf Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file2.") Return False EndIf FileWriteLine($hFileOpen, "# loading source: " & $aFileList[$i]) FileWriteLine($hFileOpen, "FFVideoSource(" & '"' & $aFileList[$i] & '"' & ")") FileWriteLine($hFileOpen, "dispWidth = 1920") FileWriteLine($hFileOpen, "dispHeight = 1080") FileWriteLine($hFileOpen, "mWidth = float(last.width)") FileWriteLine($hFileOpen, "mHeight = float(last.height)") FileWriteLine($hFileOpen, "ratio = (mWidth/mHeight)") FileWriteLine($hFileOpen, "newHeight= round(dispWidth/ratio)/2)*2") FileWriteLine($hFileOpen, "newHeight > dispHeight ? Eval(" & '"""') FileWriteLine($hFileOpen, "newHeight=dispHeight") FileWriteLine($hFileOpen, "newWidth=round((newHeight*ratio)/2)*2") FileWriteLine($hFileOpen, '"""' & ") : Eval(" & '"""') FileWriteLine($hFileOpen, "newWidth=dispWidth") FileWriteLine($hFileOpen, '"""' & ")") FileWriteLine($hFileOpen, "SR(newWidth,newHeight)") Next Next EndFunc ;==>Example but I have this error "F:\Gloria\3\mod_ok - Copia.au3" (31) : ==> Subscript used on non-accessible variable.: For $i = 1 To $aFileList[0] For $i = 1 To $aFileList^ ERROR ->03:12:59 AutoIt3.exe ended.rc:1 Edited November 7, 2016 by trof Link to comment Share on other sites More sharing options...
rootx Posted November 7, 2016 Share Posted November 7, 2016 5 hours ago, trof said: Thanks, that's what I want. One last thing. I, also, created this script expandcollapse popup#include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <File.au3> Example2() Func Example2() Local $aFileavi = _FileListToArray(@ScriptDir & "\", "*.avi") Local $path = @ScriptDir For $i = 1 To $aFileavi[0] Local $sFilePath = $aFileavi[$i] & ".avs" ConsoleWrite($sFilePath & @CRLF) FileWrite(FileOpen(@DesktopDir & "/log.txt", 2), $sFilePath) ShellExecuteWait(@DesktopDir & "/log.txt") ; Create a temporary file to write data to. If Not FileWrite($sFilePath, "LoadPlugin(" & '"' & "C:\Program Files (x86)\AviSynth+\plugins+\avssr.dll" & '"' & ")" & @CRLF) Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.") Return False EndIf Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file2.") Return False EndIf FileWriteLine($hFileOpen, "# loading source: " & $aFileavi[$i]) FileWriteLine($hFileOpen, "FFVideoSource(" & '"' & $aFileavi[$i] & '"' & ")") FileWriteLine($hFileOpen, "dispWidth = 1920") FileWriteLine($hFileOpen, "dispHeight = 1080") FileWriteLine($hFileOpen, "mWidth = float(last.width)") FileWriteLine($hFileOpen, "mHeight = float(last.height)") FileWriteLine($hFileOpen, "ratio = (mWidth/mHeight)") FileWriteLine($hFileOpen, "newHeight= round(dispWidth/ratio)/2)*2") FileWriteLine($hFileOpen, "newHeight > dispHeight ? Eval(" & '"""') FileWriteLine($hFileOpen, "newHeight=dispHeight") FileWriteLine($hFileOpen, "newWidth=round((newHeight*ratio)/2)*2") FileWriteLine($hFileOpen, '"""' & ") : Eval(" & '"""') FileWriteLine($hFileOpen, "newWidth=dispWidth") FileWriteLine($hFileOpen, '"""' & ")") FileWriteLine($hFileOpen, "SR(newWidth,newHeight)") Next EndFunc ;==>Example It works well on avi files, so I tried to use it even with other video extensions. expandcollapse popup#include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <File.au3> Example() Func Example() Local $aArray[16] $aArray[0] = ".asf" $aArray[1] = ".avi" $aArray[2] = ".divx" $aArray[3] = ".flv" $aArray[4] = ".mkv" $aArray[5] = ".mov" $aArray[6] = ".mp4" $aArray[7] = ".mpe" $aArray[8] = ".mpeg" $aArray[9] = ".mpg" $aArray[10] = ".ts" $aArray[11] = ".vob" $aArray[12] = ".wmv" $aArray[13] = ".xvid" $aArray[14] = ".h264" $aArray[15] = ".h265" For $vElement In $aArray Local $aFileList = _FileListToArray(@ScriptDir & "\", $vElement) Local $path = @ScriptDir For $i = 1 To $aFileList[0] Local $sFilePath = $aFileList[$i] & ".avs" ConsoleWrite($sFilePath & @CRLF) FileWrite(FileOpen(@DesktopDir & "/log.txt", 2), $sFilePath) ShellExecuteWait(@DesktopDir & "/log.txt") ; Create a temporary file to write data to. If Not FileWrite($sFilePath, "LoadPlugin(" & '"' & "C:\Program Files (x86)\AviSynth+\plugins+\avssr.dll" & '"' & ")" & @CRLF) Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.") Return False EndIf Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file2.") Return False EndIf FileWriteLine($hFileOpen, "# loading source: " & $aFileList[$i]) FileWriteLine($hFileOpen, "FFVideoSource(" & '"' & $aFileList[$i] & '"' & ")") FileWriteLine($hFileOpen, "dispWidth = 1920") FileWriteLine($hFileOpen, "dispHeight = 1080") FileWriteLine($hFileOpen, "mWidth = float(last.width)") FileWriteLine($hFileOpen, "mHeight = float(last.height)") FileWriteLine($hFileOpen, "ratio = (mWidth/mHeight)") FileWriteLine($hFileOpen, "newHeight= round(dispWidth/ratio)/2)*2") FileWriteLine($hFileOpen, "newHeight > dispHeight ? Eval(" & '"""') FileWriteLine($hFileOpen, "newHeight=dispHeight") FileWriteLine($hFileOpen, "newWidth=round((newHeight*ratio)/2)*2") FileWriteLine($hFileOpen, '"""' & ") : Eval(" & '"""') FileWriteLine($hFileOpen, "newWidth=dispWidth") FileWriteLine($hFileOpen, '"""' & ")") FileWriteLine($hFileOpen, "SR(newWidth,newHeight)") Next Next EndFunc ;==>Example but I have this error "F:\Gloria\3\mod_ok - Copia.au3" (31) : ==> Subscript used on non-accessible variable.: For $i = 1 To $aFileList[0] For $i = 1 To $aFileList^ ERROR ->03:12:59 AutoIt3.exe ended.rc:1 In the first example .... if you have 0 file .avi in the folder, the array variable is not accessible and your script crash... Etc.... USE this #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <File.au3> Example2() Func Example2() Local $aArray[16] $aArray[0] = ".asf" $aArray[1] = ".avi" $aArray[2] = ".divx" $aArray[3] = ".flv" $aArray[4] = ".mkv" $aArray[5] = ".mov" $aArray[6] = ".mp4" $aArray[7] = ".mpe" $aArray[8] = ".mpeg" $aArray[9] = ".mpg" $aArray[10] = ".ts" $aArray[11] = ".vob" $aArray[12] = ".wmv" $aArray[13] = ".xvid" $aArray[14] = ".h264" $aArray[15] = ".h265" For $x = 0 to UBound($aArray)-1 $file = _FileListToArray(@ScriptDir, "*"& $aArray[$x]&'"') For $z = 1 To UBound($file)-1 ConsoleWrite($x & " " &$file[$z]&@crlf) Next Next Link to comment Share on other sites More sharing options...
trof Posted November 7, 2016 Author Share Posted November 7, 2016 Again the same problem expandcollapse popup#include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <File.au3> Example() Func Example() Local $aArray[16] $aArray[0] = ".asf" $aArray[1] = ".avi" $aArray[2] = ".divx" $aArray[3] = ".flv" $aArray[4] = ".mkv" $aArray[5] = ".mov" $aArray[6] = ".mp4" $aArray[7] = ".mpe" $aArray[8] = ".mpeg" $aArray[9] = ".mpg" $aArray[10] = ".ts" $aArray[11] = ".vob" $aArray[12] = ".wmv" $aArray[13] = ".xvid" $aArray[14] = ".h264" $aArray[15] = ".h265" For $vElement In $aArray For $x = 0 To UBound($aArray) - 1 $aFileList = _FileListToArray(@ScriptDir, "*" & $aArray[$x] & '"') Local $path = @ScriptDir For $i = 1 To UBound($aFileList) - 1 ConsoleWrite($x & " " & $aFileList[$i] & @CRLF) Next Next Local $sFilePath = $aFileList[$i] & ".avs" ConsoleWrite($sFilePath & @CRLF) FileWrite(FileOpen(@DesktopDir & "/log.txt", 2), $sFilePath) ShellExecuteWait(@DesktopDir & "/log.txt") ; Create a temporary file to write data to. If Not FileWrite($sFilePath, "LoadPlugin(" & '"' & "C:\Program Files (x86)\AviSynth+\plugins+\avssr.dll" & '"' & ")" & @CRLF) Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.") Return False EndIf Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file2.") Return False EndIf FileWriteLine($hFileOpen, "# loading source: " & $aFileList[$i]) FileWriteLine($hFileOpen, "FFVideoSource(" & '"' & $aFileList[$i] & '"' & ")") FileWriteLine($hFileOpen, "dispWidth = 1920") FileWriteLine($hFileOpen, "dispHeight = 1080") FileWriteLine($hFileOpen, "mWidth = float(last.width)") FileWriteLine($hFileOpen, "mHeight = float(last.height)") FileWriteLine($hFileOpen, "ratio = (mWidth/mHeight)") FileWriteLine($hFileOpen, "newHeight= round(dispWidth/ratio)/2)*2") FileWriteLine($hFileOpen, "newHeight > dispHeight ? Eval(" & '"""') FileWriteLine($hFileOpen, "newHeight=dispHeight") FileWriteLine($hFileOpen, "newWidth=round((newHeight*ratio)/2)*2") FileWriteLine($hFileOpen, '"""' & ") : Eval(" & '"""') FileWriteLine($hFileOpen, "newWidth=dispWidth") FileWriteLine($hFileOpen, '"""' & ")") FileWriteLine($hFileOpen, "SR(newWidth,newHeight)") Next EndFunc ;==>Example I have this error "F:\Gloria\3\mod_ok - Copia.au3" (36) : ==> Subscript used on non-accessible variable.: Local $sFilePath = $aFileList[$i] & ".avs" Local $sFilePath = $aFileList^ ERROR ->10:06:47 AutoIt3.exe ended.rc:1 Link to comment Share on other sites More sharing options...
j0kky Posted November 7, 2016 Share Posted November 7, 2016 (edited) You have to add an error checking after _FileListToArray function: if @error Then ContinueLoop Edited November 7, 2016 by j0kky Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
trof Posted November 7, 2016 Author Share Posted November 7, 2016 expandcollapse popup#include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <File.au3> Example() Func Example() Local $aArray[16] $aArray[0] = ".asf" $aArray[1] = ".avi" $aArray[2] = ".divx" $aArray[3] = ".flv" $aArray[4] = ".mkv" $aArray[5] = ".mov" $aArray[6] = ".mp4" $aArray[7] = ".mpe" $aArray[8] = ".mpeg" $aArray[9] = ".mpg" $aArray[10] = ".ts" $aArray[11] = ".vob" $aArray[12] = ".wmv" $aArray[13] = ".xvid" $aArray[14] = ".h264" $aArray[15] = ".h265" For $vElement In $aArray For $x = 0 To UBound($aArray) - 1 $aFileList = _FileListToArray(@ScriptDir, "*" & $aArray[$x] & '"') Local $path = @ScriptDir For $i = 1 To UBound($aFileList) - 1 ConsoleWrite($x & " " & $aFileList[$i] & @CRLF) Next Next If @error Then ContinueLoop Local $sFilePath = $aFileList[$i] & ".avs" ConsoleWrite($sFilePath & @CRLF) FileWrite(FileOpen(@DesktopDir & "/log.txt", 2), $sFilePath) ShellExecuteWait(@DesktopDir & "/log.txt") ; Create a temporary file to write data to. If Not FileWrite($sFilePath, "LoadPlugin(" & '"' & "C:\Program Files (x86)\AviSynth+\plugins+\avssr.dll" & '"' & ")" & @CRLF) Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.") Return False EndIf Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file2.") Return False EndIf FileWriteLine($hFileOpen, "# loading source: " & $aFileList[$i]) FileWriteLine($hFileOpen, "FFVideoSource(" & '"' & $aFileList[$i] & '"' & ")") FileWriteLine($hFileOpen, "dispWidth = 1920") FileWriteLine($hFileOpen, "dispHeight = 1080") FileWriteLine($hFileOpen, "mWidth = float(last.width)") FileWriteLine($hFileOpen, "mHeight = float(last.height)") FileWriteLine($hFileOpen, "ratio = (mWidth/mHeight)") FileWriteLine($hFileOpen, "newHeight= round(dispWidth/ratio)/2)*2") FileWriteLine($hFileOpen, "newHeight > dispHeight ? Eval(" & '"""') FileWriteLine($hFileOpen, "newHeight=dispHeight") FileWriteLine($hFileOpen, "newWidth=round((newHeight*ratio)/2)*2") FileWriteLine($hFileOpen, '"""' & ") : Eval(" & '"""') FileWriteLine($hFileOpen, "newWidth=dispWidth") FileWriteLine($hFileOpen, '"""' & ")") FileWriteLine($hFileOpen, "SR(newWidth,newHeight)") Next EndFunc Now the script is executed without errors, but no avs file is created Link to comment Share on other sites More sharing options...
j0kky Posted November 7, 2016 Share Posted November 7, 2016 (edited) Try this one: expandcollapse popup#include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <File.au3> Example() Func Example() Local $aArray[16] $aArray[0] = ".asf" $aArray[1] = ".avi" $aArray[2] = ".divx" $aArray[3] = ".flv" $aArray[4] = ".mkv" $aArray[5] = ".mov" $aArray[6] = ".mp4" $aArray[7] = ".mpe" $aArray[8] = ".mpeg" $aArray[9] = ".mpg" $aArray[10] = ".ts" $aArray[11] = ".vob" $aArray[12] = ".wmv" $aArray[13] = ".xvid" $aArray[14] = ".h264" $aArray[15] = ".h265" For $vElement In $aArray $aFileList = _FileListToArray(@ScriptDir, "*" & $vElement) If @error Then ContinueLoop For $i = 1 To UBound($aFileList) - 1 Local $sFilePath = $aFileList[$i] & ".avs" If Not FileWrite($sFilePath, "LoadPlugin(" & '"' & "C:\Program Files (x86)\AviSynth+\plugins+\avssr.dll" & '"' & ")" & @CRLF) Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.") Return False EndIf Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file2.") Return False EndIf FileWriteLine($hFileOpen, "# loading source: " & $aFileList[$i]) FileWriteLine($hFileOpen, "FFVideoSource(" & '"' & $aFileList[$i] & '"' & ")") FileWriteLine($hFileOpen, "dispWidth = 1920") FileWriteLine($hFileOpen, "dispHeight = 1080") FileWriteLine($hFileOpen, "mWidth = float(last.width)") FileWriteLine($hFileOpen, "mHeight = float(last.height)") FileWriteLine($hFileOpen, "ratio = (mWidth/mHeight)") FileWriteLine($hFileOpen, "newHeight= round(dispWidth/ratio)/2)*2") FileWriteLine($hFileOpen, "newHeight > dispHeight ? Eval(" & '"""') FileWriteLine($hFileOpen, "newHeight=dispHeight") FileWriteLine($hFileOpen, "newWidth=round((newHeight*ratio)/2)*2") FileWriteLine($hFileOpen, '"""' & ") : Eval(" & '"""') FileWriteLine($hFileOpen, "newWidth=dispWidth") FileWriteLine($hFileOpen, '"""' & ")") FileWriteLine($hFileOpen, "SR(newWidth,newHeight)") Next Next EndFunc ;==>Example EDIT: Use this one! Edited November 7, 2016 by j0kky trof 1 Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
trof Posted November 7, 2016 Author Share Posted November 7, 2016 Yes, it works Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now