working on it ...

Filters

Explore Public Snippets

Sort by

Found 3,612 snippets

    public by juntalis  1598  9  5  0

    Common-use functions for batch

    A collection of utility functions for use in Windows batch scripts. Functions near the bottom may or may not cleanly work in all situations. Still need to work the kinks out of them.
    @echo off
    
    :dirname
    rem Given a filepath, resolve the absolute filepath of its parents folder.
    rem \param [out] %1 - The variable name to output the results to.
    rem \param [in]  %2 - The filepath that we'll be operating on.
    call set "%~1=%%~dp2"
    call set "%~1=%%%~1:~0,-1%%"
    goto :EOF
    
    :filename
    rem Given a filepath, extract the filename. (name and file extension)
    rem \param [out] %1 - The variable name to output the results to.
    rem \param [in]  %2 - The filepath that we'll be operating on.
    call set "%~1=%~nx2"
    goto :EOF
    
    :basename
    rem Given a filepath, extract the basename. (name without file extension)
    rem \param [out] %1 - The variable name to output the results to.
    rem \param [in]  %2 - The filepath that we'll be operating on.
    call set "%~1=%~n2"
    goto :EOF
    
    :abspath
    rem Resolve the absolute filepath to a file or folder.
    rem \param [out] %1 - The variable name to output the results to.
    rem \param [in]  %2 - The filepath that we'll be operating on.
    call set "%~1=%~f2"
    goto :EOF
    
    :which
    rem Get the path of the program in arg 2 and set the variable who's
    rem name was specified in the first argument.
    rem \param [out] %1 - The variable name to output the executable path to.
    rem \param [in]  %2 - The executable name to search for.
    call set "%~1=%~f$PATH:2"
    goto :EOF
    
    :trimslashes
    rem Trims all trailing '/' and '\')from a variable.
    rem \param [inout] %1 - The name of the variable we'll be operating on.
    call set "__C=%%%~1:~-1%%"
    if not "%__C%x"=="\x" if not "%__C%x"=="/x" (set "__C=" & goto :EOF)
    call set "%~1=%%%~1:~0,-1%%"
    goto trimslashes
    
    :strlen
    rem Determine the length of the string specified in the second argument.
    rem \param [out] %1 - The variable name to output the results to.
    rem \param [in]  %2 - The subject text that we will be measuring.
    setlocal
    set _STRLEN_BUFFER_=%~2
    set /A _STRLEN_LENGTH_=0
    :strlen_loop
    if "%_STRLEN_BUFFER_%x"=="x" goto strlen_continue
    set _STRLEN_CHAR_=%_STRLEN_BUFFER_:~0,1%
    set /A _STRLEN_LENGTH_ += 1
    set _STRLEN_BUFFER_=%_STRLEN_BUFFER_:~1%
    goto strlen_loop
    :strlen_continue
    endlocal & call set %~1=%_STRLEN_LENGTH_%
    goto :EOF
    
    :rreplace
    rem Replaces recursively.
    rem \param [out] %1 - The variable name to output the results to.
    rem \param [in]  %2 - The subject text to search and replace through.
    rem \param [in]  %3 - The substring to search for in %2.
    rem \param [in]  %4 - The replacement text to substitute when %3 is found.
    call set "%~1=%~2"
    verify>nul
    :rreplace_work
    (call echo %%%~1%%|find "%~3")>nul 2>nul
    if errorlevel 1 goto rreplace_done
    verify>nul
    call set "%~1=%%%~1:%~3=%~4%%"
    goto rreplace_work
    :rreplace_done
    verify>nul
    goto :EOF
    
    :tolower
    rem Subroutine to convert a variable VALUE to all lower case.
    rem The argument for this subroutine is the variable NAME.
    for %%C in ("A=a" "B=b" "C=c" "D=d" "E=e" "F=f" "G=g" "H=h" "I=i" "J=j" "K=k" "L=l" "M=m" "N=n" "O=o" "P=p" "Q=q" "R=r" "S=s" "T=t" "U=u" "V=v" "W=w" "X=x" "Y=y" "Z=z") do @call set "%~1=%%%~1:%%~C%%"
    goto :EOF
    
    :isdefined
    rem Checks if a variable has a defined value.
    if "%~1x"=="x" exit /B 1
    if not defined %~1 exit /B 1
    goto :EOF
    
    :splitenv
    rem Given an expandable environment variable such as PATH or PATHEXT,
    rem split the variable into its individual lowercase components such that the
    rem value of:
    rem   .COM;.BAT;.EXE
    rem would expand into:
    rem   ".COM" ".BAT" ".EXE"
    rem The resulting value should be suitable for using with the FOR command.
    call set %~1=%%%~2:;=" "%%
    call set %~1="%%%~1%%"
    call :tolower "%~1"
    goto :EOF
    
    :whichex
    rem Similar to the original which above, but with additional functionality
    rem to use the PATHEXT variable when the executable is specified without a
    rem file extension. (ex: Specifying cmd.exe as cmd)
    rem \param [out] %1 - The variable name to output the executable path to.
    rem \param [in]  %2 - The executable name to search for.
    setlocal
    set _WHICHEX_TARGET_=%~2
    call :which _WHICHEX_RESULT_ "%_WHICHEX_TARGET_%"
    if exist "%_WHICHEX_RESULT_%" goto whichex_success
    if not "%~x2x"=="x" goto whichex_failure
    goto whichex_pathext
    :whichex_testpath
    rem Given a file basename and extension, see if we can find a matching
    rem executable on the system PATH.
    if errorlevel 1 exit /B %ERRORLEVEL%
    call :which _WHICHEX_RESULT_ "%~1%~2"
    if exist "%_WHICHEX_RESULT_%" exit /B 1
    goto :EOF
    :whichex_pathext
    rem No file extension was found on our executable name. First we'll try
    rem a search with no extension, (as it was specified) and if that fails,
    rem we'll try the search again with each file extension in PATHEXT until
    rem we find a match. (or run out of extensions)
    call :splitenv _WHICHEX_PATHEXT_ PATHEXT
    for %%E in (%_WHICHEX_PATHEXT_%) do @call :whichex_testpath "%~nx2" "%%~E"
    rem When an executable is found, the errorcode is set to 1 to indicate success.
    if errorlevel 1 goto whichex_success
    rem If it's still zero at this point, that means we failed to find our executable.
    goto whichex_failure
    :whichex_success
    rem We maanged to resolve the executable path, which is now stored in a
    rem localized variable named _WHICHEX_RESULT_. Copy that value over to
    rem our outgoing parameter and cleanup.
    verify>nul
    call set _WHICHEX_COPYCMD_=set "%~1=%_WHICHEX_RESULT_%"
    endlocal & call %_WHICHEX_COPYCMD_%
    goto :EOF
    :whichex_failure
    rem We failed to find the executable path based on the info given. Clean
    rem up and report the error.
    set _WHICHEX_RESULT_=
    endlocal
    call set %~1=%_WHICHEX_RESULT_%
    exit /B 1
    
    
                            

    public by TristinDavis  1386  2  3  0

    CI WebDeploy using MSBuild - Creates WebDeployment package and then deploys that package using the given published profile name

    CI WebDeploy using MSBuild - Creates WebDeployment package and then deploys that package using the given published profile name: msbuild-webdeploy.commandline.cmd
    ## Deployment Step ##
    
    ```
    MSBuild.exe C:\Projects\Class.csproj /P:Configuration=Debug /P:DeployOnBuild=true /P:DeployTarget=Package /P:PublishProfile=ClassOnlineProduction /P:_PackageTempDir=C:\packages /P:CreatePackageOnPublish=True /P:VisualStudioVersion=14.0
    ```
    
    
    

    public by Fresh-Dev  2701  4  3  0

    Zips every subdirectory as a seperate archive file.

    Zips every subdirectory as a seperate archive file.: zipSubdirectorys.bat
    FOR /D %%i IN (%1) 
        DO "c:\Program Files (x86)\7-Zip\7z.exe" a "%%i.zip" "%%i\"
    
    

    public by LongBeard  1788  0  3  0

    Zips every subdirectory as a seperate archive file.

    Zips every subdirectory as a seperate archive file.: zipSubdirectorys.bat
    FOR /D %%i IN (%1) 
        DO "c:\Program Files (x86)\7-Zip\7z.exe" a "%%i.zip" "%%i\"
    
    

    public by Alessio Felicioni  9016  1  4  1

    scheduled task command, windows host (warning: not just a CTRL+C & CTRL+V crontab replacement). Scheduled for every Monday at 20:15

    scheduled task command, windows host (warning: not just a CTRL+C & CTRL+V crontab replacement). Scheduled for every Monday at 20:15: windows-scheduled-task.cmd
    schtasks /create /tn "Namespace\Scheduled Task" /tr "php -f C:\xampp\htdocs\index.php" /sc weekly /d MON /st 20:15
    
    

    public by Steve Reich  2062  0  3  0

    This file will enable/disable the Windows built-in administrator account. This account is disabled by default, but is sometimes needed in order to have certain permissions. Be sure you run this file as administrator or assign the appropriate permission...

    This file will enable/disable the Windows built-in administrator account. This account is disabled by default, but is sometimes needed in order to have certain permissions. Be sure you run this file as administrator or assign the appropriate permissions to execute it.: toggleAdministratorAccount.bat
    :: This will enable/disable the Windows built-in administrator account.
    :: Run this file as "Run as administrator", and then at the prompt, enter
    :: one of the following options: y | n | yes | no ... the /i flag makes the
    :: options case insensitive, so either capital or lower case is accepted. 
    :: Enter any other value, or no value at all, will return an error message
    :: and not run the command.
    ECHO OFF
    SETLOCAL
    SET /P doAdmin="Enable Windows built-in administrator account? (y/n) "
    IF /i "%doAdmin%" EQU "n" SET doAdmin=no
    IF /i "%doAdmin%" EQU "y" SET doAdmin=yes
    IF NOT DEFINED doAdmin (
    	ECHO No action was taken. User input is required.
    	PAUSE
    	EXIT
    ) ELSE (
    	IF /i "%doAdmin%" EQU "no" (
    		SET domainLabel=disabled
    		net user administrator /active:%doAdmin%
    		GOTO runAdmin
    	)
    	IF /i "%doAdmin%" EQU "yes" (
    		SET domainLabel=enabled
    		net user administrator /active:%doAdmin%
    		GOTO runAdmin
    	)
    	ECHO No action was taken. "%doAdmin%" is not a valid option.
    	PAUSE
    	EXIT
    )
    :runAdmin
    	ECHO The built in administrator has been %domainLabel%
    	PAUSE
    ENDLOCAL
    EXIT
    
    

    public by aknorr  171896  0  3  0

    convert VHD file to RAW Image

    convert VHD file to RAW Image: vhd2raw.cmd
    qemu-img convert -O raw source.vhd output.raw
    
    

    public by fushihara  158538  0  3  0

    簡単作業ディレクトリ

    簡単作業ディレクトリ: createTempDir.bat
    @echo off
    set dateStr=%date%
    set timeStr=%time%
    set dateStr=%dateStr:/=-%
    set dateStr=%dateStr: =0%
    set timeStr=%timeStr::=-%
    set timeStr=%timeStr: =0%
    set new_temp_path=%TMP%\temp_%dateStr%_%timeStr%\
    mkdir "%new_temp_path%"
    explorer "%new_temp_path%"
    
    
    

    public by juntalis  842  0  3  0

    Utility batch script to locate Visual Studio installation

    Utility batch script to locate Visual Studio installation: find-msvc.cmd
    @echo off
    rem Usage: find-msvc.cmd MinimumVersion MaximumVersion
    rem 
    rem Given a range of versions to search for, this script attempts to locate a 
    rem valid Visual Studio installation based upon the current set of environment 
    rem variables. If a valid installation is found, this script sets the 
    rem environment variable "VCROOT" to  Drive:\Path\To\VS\VC. On success, we 
    rem should be able to call %VCROOT%\vcvarsall.bat.
    rem
    rem Versions use the VSXX0COMNTOOLS environment variable:
    rem 
    rem     VS 2015 => 13
    rem     VS 2013 => 12
    rem     VS 2012 => 11
    rem     VS 2010 => 10
    rem     VS 2008 => 9
    rem     VS 2005 => 8
    rem 
    rem Example
    rem     call find-msvc.cmd 8 13
    rem     if errorlevel 1 exit /B %ERRORLEVEL%
    rem     call "%VCROOT%\vcvarsall.bat" x86
    rem
    rem or
    rem     call find-msvc.cmd 13 8
    rem     if errorlevel 1 exit /B %ERRORLEVEL%
    rem     call "%VCROOT%\vcvarsall.bat" amd64
    rem
    rem TODO: Add the ability to specify a preferred version. (A version to search
    rem       for, even after the script discovered a working installation. if not
    rem       found, the script will fall back onthe valid installation it did find)
    setlocal
    
    :forkcheck
    rem Since this batch file executes self executes, it's important that we make
    rem sure there's no chance of it repeating its previous logic, which would
    rem result in an infinite recursively executing script. (fork bomb for lack
    rem of a better term) This could've easily been handled with a simple "if 
    rem defined" guard, but I felt like tracking the nesting level for shits and
    rem giggles.
    rem 
    rem Since each nested invocation of the script will copy the previous
    rem environment before localizing it, (line 27: setlocal) the value of 
    rem CMD_FORK_LEVEL will steadily increment with each nesting level. When an
    rem invocation has completd its execution of the script, it will return to
    rem the previous nesting level, and revert back to the previous environment.
    rem This will have the effect of CMD_FORK_LEVEL's value decrementing by one.
    if not defined CMD_FORK_LEVEL (
    	set /A CMD_FORK_LEVEL=1
    ) else (
    	set /A CMD_FORK_LEVEL=%CMD_FORK_LEVEL% + 1
    )
    if %CMD_FORK_LEVEL% GTR 1 goto forked
    
    :getopts
    rem Figure out the minimum and maximum version numbers, as well as the
    rem direction that we'll be searching in.
    set _VC_STEP_VERSION_=1
    if "%~1x"=="x" set _VC_MIN_VERSION_=8
    if "%~2x"=="x" set _VC_MAX_VERSION_=13
    if not defined _VC_MIN_VERSION_ set _VC_MIN_VERSION_=%~1
    if not defined _VC_MAX_VERSION_ set _VC_MAX_VERSION_=%~2
    if %_VC_MIN_VERSION_% GTR %_VC_MAX_VERSION_% set /A _VC_STEP_VERSION_=-1
    goto main
    
    :forked
    if not "%VCVERS%x"=="x" goto forked_cleanup
    call set "TESTVERS=%%VS%~10COMNTOOLS%%"
    if "%TESTVERS%x"=="x" goto forked_cleanup
    if not exist "%TESTVERS%" goto forked_cleanup
    endlocal & set VCVERS=%~1
    goto :EOF
    :forked_cleanup
    endlocal
    goto :EOF
    
    :dirname
    rem Get the dirname of the second argument and set the variable who's
    rem name was specified in the first argument.
    call set %~1=%%~dp2
    call set %~1=%%%~1:~0,-1%%
    goto :EOF
    
    :main
    rem We'll start by finding the first existing install of msvc
    set VCVERS=
    set VCYEAR=
    set VCROOT=
    for /L %%V in (%_VC_MIN_VERSION_%,%_VC_STEP_VERSION_%,%_VC_MAX_VERSION_%) do @call "%~f0" %%~V
    if "%VCVERS%x"=="x" goto notfound
    endlocal & set VCVERS=%VCVERS%
    
    :vcyear
    rem Based on the version, we can figure out the year.
    rem 13 => VS 2015
    rem 12 => VS 2013
    rem 11 => VS 2012
    rem 10 => VS 2010
    rem 9  => VS 2008
    rem 8  => VS 2005
    if "%VCVERS%"=="8"  set VCYEAR=2005
    if "%VCVERS%"=="9"  set VCYEAR=2008
    if "%VCVERS%"=="10" set VCYEAR=2010
    if "%VCVERS%"=="11" set VCYEAR=2012
    if "%VCVERS%"=="12" set VCYEAR=2013
    if "%VCVERS%"=="13" set VCYEAR=2015
    
    :vcroot
    rem Finally, let's determine the root folder for this VC installation.
    call set VCROOT=%%VS%VCVERS%0COMNTOOLS%%
    if "%VCROOT:~-1%"=="\" set VCROOT=%VCROOT:~0,-1%
    rem VCROOT=VSDir\Common7\Tools
    call :dirname VCROOT "%VCROOT%"
    rem VCROOT=VSDir\Common7
    call :dirname VCROOT "%VCROOT%"
    rem VCROOT=VSDir
    set VCROOT=%VCROOT%\VC
    goto :EOF
    
    :notfound
    echo Could not locate a valid MSVC version.
    endlocal
    exit /B 1
    
    
    

    public by lbottaro  341335  3  7  1

    How to checkout the latest tag of a Git repository

    This simple bash script allows to automatically checkout your local git repository on the latest tagged version available on the remote repository. The script assumes to be run from your local repo. The command 'git rev-list --tags' lists the tags IDs in reverse chronological order, getting the very last one on top. The command 'git describe
    # Get new tags from the remote
    git fetch --tags
     
    # Get the latest tag name
    latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)
     
    # Checkout the latest tag
    git checkout $latestTag  
    • Public Snippets
    • Channels Snippets