Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BATCH ] getting output in a variable

Status
Not open for further replies.

0318

Programmer
Jan 18, 2004
25
0
0
NL
hi people.
i have a script that obtains the owner of a file. i can echo the owner on the screen, and i can write the owner into a textfile.
the thing is, another script needs to send a email to the owner. so the owner have to be a variable. How do i do that?
ok, here is a piece of code that ECHO's the owner and writes it to c:\owner.txt

FOR /F "skip=5 tokens=5* delims=\ " %%A IN ('DIR/A-D/Q "%OwnedFile%" ^| FIND /V "(s)"') DO ECHO.%%A >> c:\owner.txt

i need the owner in a variable. ive tried the following:

FOR /F "skip=5 tokens=5* delims=\ " %%A IN ('DIR/A-D/Q "%OwnedFile%" ^| FIND /V "(s)"') DO SET FILEOWNER=%%A

so now, FILEOWNER should include the owner, but when i trie to echo the variable it doesnt do anything:

ECHO the owner is %FILEOWNER%

am i doing something wrong?

( maybe another solution. i can write the owner into a text file, maybe its easy to make a script that gets the name out of the text file and puts it into a variable? )

i hope someone can help me, im struggling along time with this problem..

greetings,

Andre
 
============ UPDATE =================

its ok now!!! after that peace of code, there was a ENDLOCAL. But i didnt knew what ENDLOCAL was.
i can now ECHO the variable.
BUT.. it contains only 1 variable, so i can ECHO one owner on the screen. When i have 2 or more files in the directory wich the script scans, it gives output like:

owner is Administrators
owner is
owner is

so i have to make a loop in the script i guess.

someone a idea?

here is the full script, ( big piece of it is not important )

@ECHO OFF

Rem gemaakt door : Andre Jochemsen
rem Datum : 7 april 2004
rem Laatste wijziging : 20 april 2004


ECHO.

:: Checken Windows versie
VER | FIND /V "Windows 2000" >NUL
IF NOT ERRORLEVEL 1 GOTO Start
VER | FIND /V "Windows XP" >NUL
IF ERRORLEVEL 1 GOTO WrongVer

:Start


:: Check command line parameter
SET OwnedFile=%1
IF NOT DEFINED OwnedFile GOTO Syntax
SET OwnedFile=%OwnedFile:"=%
IF "%OwnedFile%"=="/?" GOTO Syntax
IF NOT EXIST "%OwnedFile%" GOTO Syntax
IF EXIST "%OwnedFile%\" GOTO Syntax

:: Does filespec contain wildcards?
ECHO.%OwnedFile% | FIND "?" >NUL
IF NOT ERRORLEVEL 1 GOTO Multiple
ECHO.%OwnedFile% | FIND "*" >NUL
IF NOT ERRORLEVEL 1 GOTO Multiple


:Multiple
:: Show owner of specified files; display owner and file name
FOR /F "skip=5 tokens=5* delims=\ " %%A IN ('DIR/A-D/Q "%OwnedFile%" ^| FIND /V "(s)"') DO SET OWNERFILE=%%A >> c:\owner.txt
GOTO End

:WrongVer
ECHO Dit batch bestand kan alleen gebruikt worden onder windows 2000
GOTO End

:Syntax
ECHO syntax my ass
ECHO.


:End
ECHO owner is %OWNERFILE%



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top