Windows batch

From bernie's
Jump to: navigation, search

CMBLine tips: http://www.dostips.com/DtCodeSnippets.php

Create gif from sequence with imagemagick

Use with filemenutools and imagemagick (with IM's path in the system/env path)

Dim arr(4)
q = chr(34)
l = 0
arg1 = Wscript.Arguments(0)
Set re = new regexp
re.IgnoreCase = True
re.Global = True
re.Pattern = "(.*)([_|\.]\d*)\.([a-zA-Z]{2,4})"
  Set matches = re.Execute(arg1)
  If matches.Count > 0 Then
    Set match = matches(0)
    l = l + 1
    arr(l) = match.Value
    If match.SubMatches.Count > 0 Then
      For I = 0 To match.SubMatches.Count-1
              l = l + 1
              arr(l) = match.SubMatches(I)
      Next
      originalSeq = arr(2)+Left(arr(3),1)+"*."+arr(4)
      gifname = arr(2)+Left(arr(3),1)+".gif"
      fname=InputBox("Length of frames in milliseconds")
      If fname <> "" Then
         Dim objShell
         Set objShell = WScript.CreateObject ("WScript.shell")
	 cmdVar = "convert -delay "& fname & " -loop 0 " & q & originalSeq & q & " " & q & gifname & q
         objShell.run "cmd /K "+cmdVar+" & echo. & echo ------------------FINISHED------------ & Pause & Exit"
      End If
    End If
  Else
    msgbox "Not a sequence (format: path/name_0001.ext or name.01.ext )", 0, "sequence processing"
  End If

Render sequence from shell

ZB4Lu.png

Dim arr(4)
l = 0
arg1 = Wscript.Arguments(0)
Set re = new regexp
re.IgnoreCase = True
re.Global = True
re.Pattern = "(.*)([_|\.]\d*)\.([a-zA-Z]{2,4})"
  Set matches = re.Execute(arg1)
  If matches.Count > 0 Then
    Set match = matches(0)
    l = l + 1
    arr(l) = match.Value
    If match.SubMatches.Count > 0 Then
      For I = 0 To match.SubMatches.Count-1
              l = l + 1
              arr(l) = match.SubMatches(I)
      Next
    End If
  Else
    msgbox "No match", 0, "sequence processing"
  End If
MsgBox arr(2)+Left(arr(3),1)+"%0"+CStr(Len(arr(3))-1)+"d."+arr(4)

Find % of space left on drives (WIN)

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DriveType = 3")
For Each objDisk in colDisks
    intFreeSpace = objDisk.FreeSpace
    intTotalSpace = objDisk.Size
    pctFreeSpace = intFreeSpace / intTotalSpace
    Wscript.Echo objDisk.DeviceID, FormatPercent(pctFreeSpace)
Next

Windows text 2 speech

Option Explicit
Dim caca
caca = WScript.Arguments(0)
CreateObject("SAPI.SpVoice").Speak caca

Wake on lan freebox: http://michauko.org/blog/2007/07/03/wake-on-lan-et-freebox/comment-page-1/#comment-2709

Powershell remove empty directories

function DeleteEmptyDirectories {
  param([string] $root)

  [System.IO.Directory]::GetDirectories("$root") |
    % {
      DeleteEmptyDirectories "$_";
      if ([System.IO.Directory]::GetFileSystemEntries("$_").Length -eq 0) {
        Write-Output "Removing $_";
        Remove-Item -Force "$_";
      }
    };
}

DeleteEmptyDirectories "P:\Path\to\wherever";


EXR rezip

http://www.fevrierdorian.com/blog/public/billets/2011_03_08_images_exr_compo_lent/OpenImageIO_bin.7z

if [%1]==[] goto :eof
:loop
C:\Users\BUFFALO\Desktop\OpenImageIO_bin\iconvert.exe -v --compression zips --scanline %1 %1
shift
if not [%1]==[] goto loop

render sequence to movie

//works on png files and plays fine
ffmpeg -f image2 -i fileName.%4d.png -r 25 -vf "scale=1280:trunc(ow/a/vsub)*vsub" -y fileName.mp4 

http://x264.nl/

//doesn't really work well
x264 -i "sequence%04d.png" "output.mp4"

wait until file is created and do something

@echo off
echo waiting...
:start
PING 1.1.1.1 -n 1 -w 1000 >NUL
if EXIST test.txt start calc & goto :eof
goto start

loop some app forever

@echo off
:loopme
PING 1.1.1.1 -n 1 -w 2000 >NUL
tasklist /fi "imagename eq maya.exe" 2> NUL | find /I /N "maya.exe">NUL
if "%ERRORLEVEL%"=="1" echo Restarting maya & maya.exe
goto loopme

Loops AFX renders if it crashes

@echo off
goto start
:sequences
"C:\Program Files\Adobe\Adobe After Effects CS5\Support Files\aerender.exe" -project "E:\test.aep"
goto loopend

REM ##############################################################
REM ##############################################################

:loopme
cls
echo.
echo ^>^>^> AFX: 60s
PING 1.1.1.1 -n 1 -w 20000 >NUL
cls
echo.
echo ^>^>^> AFX: 40s
PING 1.1.1.1 -n 1 -w 20000 >NUL
cls
echo.
echo ^>^>^> AFX: 20s
PING 1.1.1.1 -n 1 -w 20000 >NUL
:start
tasklist /fi "imagename eq AfterFX.com" 2> NUL | find /I /N "AfterFX.com">NUL
if "%ERRORLEVEL%"=="1" echo Restarting After Fx & goto sequences
:loopend
goto loopme

Shutdown if render is done

@echo off
:loopme
PING 1.1.1.1 -n 1 -w 2000 >NUL
tasklist /fi "imagename eq maya.exe" 2> NUL | find /I /N "maya.exe">NUL
if "%ERRORLEVEL%"=="1" echo Shutting down pc... & shutdown -s -f -t 0
goto loopme

batch processing folders

@echo off
REM takes folders called GB********, places them in directory extracted from name using underscores, deletes originals.
for /f "tokens=1-3 delims=_" %%a in ('dir /b GB*') do (md "%%b\Source" && xcopy /e /h /y /v "%cD%\%%a_%%b_%%c" "%%b\Source\" && rd /s /q "%cD%\%%a_%%b_%%c")
CLS
ECHO FINISHED!
pause

rar files

"C:\Program Files\WinRAR\rar.exe" a -v409600 test.rar *.tga 

MAP file maker

:map
FOR /f "tokens=*" %%G IN ('dir *.%2 /x /b') DO (
imf_copy -p "%%G" "%%G.map"
)
GOTO :EOF

sequence to gif

imconvert -delay 3 -dispose Background -adjoin test_pot.*.png t.gif 

png > tga

FOR /f "tokens=*" %%G IN ('dir *.png /x /b') DO (
imgcvt -f png -t tga %%G %%Gtga
)
ren *.pngtga *.tga

conneciton au snap

net use u: \\10.54.100.20\projet08 motdpasse /USER:vprojet08


l.bat

@ECHO OFF
SET mayaversion=2012-x64
goto :getzip


REM ***************************************************
echo.
echo type "l help" for infos
echo.
GOTO %1

:vfb
%userprofile%/nircmdc.exe win center ititle "V-Ray frame"
goto :EOF

:help
start http://berniebernie.fr/wiki/index.php?title=Windows_batch#l.bat
goto :EOF

:mayatest
start %userprofile%/documents/maya/%mayaversion%
GOTO :EOF

:EDIT
PUSHD %~dp0
start notepad l.bat
POPD
GOTO :EOF

:wiki
start http://berniebernie.fr/wiki/
GOTO :EOF

:win
PUSHD "C:\Program Files (x86)\Winamp\"
start winamp.exe
POPD
GOTO :EOF

:pd
pushd L:\RESSOURCES\_LIB\INSTALLS\PDPlayer\INSTALLED\Pdplayer
start pdplayer.exe
popd
goto :EOF


:radios
bitsadmin /transfer "radios" http://mlkdesign.free.fr/dump/radios.m3u %userprofile%\Desktop\radios.m3u
PUSHD "%userprofile%\Desktop\"
start radios.m3u
POPD
GOTO :EOF

:lm
REM LOWER MAYA PROC

IF [%2]==[1] powershell "foreach ($m in (Get-Process -ProcessName "maya")) {$m.ProcessorAffinity=0x3F}" & ECHO maya* set to low
IF [%2]==[0] powershell "foreach ($m in (Get-Process -ProcessName "maya")) {$m.ProcessorAffinity=0xFF}" & ECHO maya* set to high (default)
PING 1.1.1.1 -n 1 -w 2000 >NUL
GOTO :EOF

:cvt
FOR /f "tokens=*" %%G IN ('dir *.%2 /x /b') DO (
imgcvt -f %2 -t %3 %%G %%G%3
)
ren *.%2%3 *.%3
GOTO :EOF

:k
TASKKILL /F /IM %2*
GOTO :EOF

:ke
TASKKILL /F /IM explorer.exe
start explorer
GOTO :EOF

:kall
TASKKILL /F /IM AfterFX*
TASKKILL /F /IM flash*
TASKKILL /F /IM maya*
TASKKILL /F /IM explor*
TASKKILL /F /IM muste*
TASKKILL /F /IM mudbox*
TASKKILL /F /IM photo*
TASKKILL /F /IM chrom*
TASKKILL /F /IM fire*
TASKKILL /F /IM quick*
TASKKILL /F /IM djv*
TASKKILL /F /IM fcheck*
TASKKILL /F /IM outlook*
TASKKILL /F /IM excel*
TASKKILL /F /IM vlc*
TASKKILL /F /IM console*
TASKKILL /F /IM maxwell*


start explorer
GOTO :EOF


:cvt
FOR /f "tokens=*" %%G IN ('dir *.%2 /x /b') DO (
imgcvt -f %2 -t %3 %%G %%G%3
)
ren *.%2%3 *.%3
GOTO :EOF

:lame
FOR /f "tokens=*" %%G IN ('dir *.wav /x /b') DO (
echo %%G
E:\bernie\soft_portable\lame\lame.exe -h -V 4 "%%G" "%%Gmp3"
) 
ren *.wavmp3 *.mp3
if %2 == del (del *.wav /Q)
GOTO :EOF


:sav
cls
echo.
set /p top=Sauver "%FOLDERPATH%" commentaire:
echo -------------------- >> C:\temp.txt
echo %top% >> C:\temp.txt
echo %FOLDERPATH% >> C:\temp.txt
GOTO :EOF

:savop
cls
notepad C:\temp.txt
GOTO :EOF




REM ____________________________________________________________DOWNLOAD WINZIP__________________________________________
:getzip
cls
ECHO No zipper found, downloading 7zip
ECHO _________________________________________________________
IF exist %userprofile%\Downloads\7za.exe (goto :%1)
bitsadmin /transfer "7zip utility" http://mlkdesign.free.fr/dump/7za %userprofile%\Downloads\7za.exe
goto :%1
GOTO :EOF

REM ____________________________________________________________ZIP MAYA PREFS, download 7zip if needed__________________

:mayazip
PUSHD "%userprofile%\Downloads\"
7za a -t7z %userprofile%\Downloads\%mayaversion%.7z %userprofile%\documents\maya\%mayaversion%
explorer /select,%userprofile%\Downloads\%mayaversion%.7z
POPD
GOTO :EOF

REM ____________________________________________________________LAUNCH BULK RENAME, download if needed____________________

:bru
cls
IF exist %userprofile%\Downloads\BRU (goto :brugo)
bitsadmin /transfer "bru" http://mlkdesign.free.fr/dump/BRU_NoInstall.zip %userprofile%\downloads\bru.zip
PUSHD "%userprofile%\Downloads\"
7za.exe x -y bru.zip
GOTO :brugo
:brugo
PUSHD "%userprofile%\Downloads\BRU\64-bit
"Bulk Rename Utility.exe"
POPD
GOTO :EOF

REM ____________________________________________________________SHUTDOWN IN X SECONDS_____________________________________

:shutdown
shutdown/s /t %2 /f /c "shutdown via .bat %2 seconds"
GOTO :EOF

Set maya proc affinity

$mayas = Get-Process -ProcessName "mayabatch" 
foreach ($m in $mayas) {$m.ProcessorAffinity=0x3F}