Batch Scripts
Looping FTP
Example usage would be to push a file to a set of clients
updt.bat Main executable
1
2
@echo off
FOR /F "tokens=3 delims=|" %%i in (list) DO ftp -s:updt %%i >> updt.out
ftpCmds.txt FTP Commands to run once connected
ftpServers.txt Servers and any other info you may need later
1
2
3
4
token 1|token 2|192.168.0.1 |token 4|token 5|
token 1|token 2|192.168.0.2 |token 4|token 5|
token 1|token 2|192.168.0.3 |token 4|token 5|
...
filename.exe This can be a uuencoded install script or really anything
Looping Excecutable
Similar to bash’s xargs, this allows you to iterate over each file in a directory and execute/modify
printFiles.bat
1
2
3
4
5
6
7
8
9
@ECHO OFF
SETLOCAL
set file=.\*
FOR %%i IN ("%file%") DO (
ECHO filedrive=%%~di
ECHO filepath=%%~pi
ECHO filename=%%~ni
ECHO fileextension=%%~xi
)
Create XSDs
1
for %%i in (.\*) DO xsd %%i /c /n:myNamespace.XSD.%%~ni /o:..\..\MyProject\GeneratedClasses\
Create Shortcut
Creates a shortcut to a given file
1
2
3
4
5
6
7
8
9
10
rem Creating the File Shortcut
@echo off
set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs
echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo sLinkFile = "\Path\To\Shortcut.lnk" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = "\\Path\To\File.exe" >> %SCRIPT%
echo oLink.Save >> %SCRIPT%
cscript /nologo %SCRIPT%
del %SCRIPT%