Showing posts with label batch. Show all posts
Showing posts with label batch. Show all posts

Saturday, August 6, 2011

Batch recursion

Here are 3 short scripts to demonstrate directory recursion
Script 1
@echo off
::demonstrates relative directory recursion
::does not detect hidden files

:main
for %%v in (*.*) do echo %%v
for /d %%v in (*.*) do call :sub "%%v"
goto :eof

:sub
for %%f in ("%~1\*.*") do echo %%f
for /d %%d in ("%~1\*.*") do call :sub "%%d"
goto :eof
Script 2
@echo off
::demonstrates directory recursion
::does detect hidden files but outputs fullpath
for /r %%v in (*.*) do echo %%v
Script 3
@echo off
::demonstrates directory recursion
::detects hidden files & outputs relative path

setlocal enabledelayedexpansion
for /r %%v in (*.*) do set n=%%v&echo !n:%CD%\=!

Saturday, June 18, 2011

Getting password in batch file

This batch script gets the password without displaying user input. Tested only in XP. Vbs script is required.
@echo off
echo wscript.echo CreateObject("ScriptPW.Password").GetPassword()>%temp%\getpwd.vbs
set pwd=Password: <nul
for /f "delims=" %%i in ('cscript /nologo %temp%\GetPwd.vbs') do set pwd=%%i
echo.
echo "%pwd%"
The last line shows the user password for testing purposes. Note that password must be enclosed in double quotes to prevent bad inputs that contains &.