Home - Search - Site Map - Site Graph   |  Contact  
( Last Modified: 2008 October 20th 12:16 PM )

Windows Batch File Tricks

Pipe command output into a batch variable

You can do this using the /P switch of the set command.

"The /P switch allows you to set the value of a variable to a line of input entered by the user. Displays the specified promptString before reading the line of input. The promptString can be empty." - http://www.computerhope.com/sethlp.htm

Example:

dir > temp.txt
set /P diroutput= < temp.txt

Execute a command in every directory recursively

Replace command with the required command or batch file.
It will get called for each subdirectory of the current directory. And have the directory name as the parameter variable %1.

Example:

for /f "usebackq" %%d in (`"dir /ad/b/s"`) do COMMAND "%%d"

Set NTFS permissions from a batch file

This is done with the cacls command:

Example:

cacls file.txt /e /g everyone:w

This grants (/g) the user "everyone" write access. And only edits (/e) the permissions so that current permission are left unchanged.

 

( Page Created: 2008 October 20th 12:16 PM )