Avatar of falcs2k1
falcs2k1 asked on

Need to capture archive bit value as a batch file variable

I am trying to write a batch file to perform several maintenance tasks on some VMWare virtual disks. These tasks are destructive and I only want them to run after confirming the VM files were successfully backed up.
I am trying to use the ATTRIB command to return the value of the archive bit of a file (MyDisk.VMX). If the value is "A" (i.e. set) then I want the batch file to terminate. If the archive bit value is clear, then the maintenance task can run.
I have done Internet searches with every type of wording, but I can't find any batch file syntax that will let me query for archive bit value and use the returned value in an IF-THEN / IF-ELSE subroutine.
The attached code snippet shows what I'm trying to do. Right now I am only dumping to a log file just to see what the value is, but it is just treating it like a string. Any ideas? Can this even be done in a batch file?
@ECHO OFF
 
set logfile=C:\VM_Maintenance.LOG
set Archive_Status=ATTRIB MyDisk.VMX
 
echo Batch command: %0 %* >%logfile%
echo Started at %date% %time% >>%logfile%
echo ------------------------ >>%logfile%
ECHO %Archive_Status% >>%logfile%

Open in new window

Windows BatchVMwareScripting Languages

Avatar of undefined
Last Comment
Shift-3

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Shift-3

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Gastone Canali


another way... using Conditional Execution and findstr
attrib "%file%"|findstr /b "A"&&set Archive_Status=A
http://www.ss64.com/bashsyntax/conditional.html













































































@ECHO OFF
setlocal
::  log file with standard error
set logfile=C:\VM_Maintenance.LOG 2^>^&1
::  Target file
set file=c:\vm\my os\MyDisk.VMX
:: so u find something usefull in the log
set Archive_Status=Archive status is empty
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: set the value only if the 1st char of rhe attrib result is A 
attrib "%file%"|findstr /b "A"&&set Archive_Status=A
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if "%Archive_Status%"=="A" goto :END 
::  start the maintai
echo Batch command: %0 %* >%logfile%
echo Started at %date% %time% >>%logfile%
echo ------------------------ >>%logfile%
ECHO %Archive_Status% >>%logfile%

Open in new window

Gastone Canali

Oops
ASKER
falcs2k1

THANK YOU for the rapid response. I have to deploy this to 75 servers before Memorial Day. You saved my vacation!!
Your help has saved me hundreds of hours of internet surfing.
fblack61
Shift-3

Saving your vacation is only worth a B?  Were you going to Jersey or something?