Jump to content
Macro Express Forums

Determine File Property


Recommended Posts

Hello and welcome to the forum!


This can be done through a batch file:

attrib %1 > %2

and a macro:

// T1 = DOS batch file
// T2 = File to get attribute from
// T3 = File to store results
Variable Set String %T1% "c:\temp\test.bat"
Variable Set String %T2% "c:\temp\xfer.zip"
Variable Set String %T3% "c:\temp\results.txt"

// Run the batch file and wait for the results to be written
Program Launch: "%T1%"
Wait for File Ready: "

// Parse the results file
Variable Set String %T4% from File: "%T3%"
Replace "%T2%" with "" in %T4%
Variable Modify String: Trim %T4%

// Test for an "R"
If Variable %T4% contains "R"
 Text Box Display: 
 Text Box Display: 
End If
Macro Return

<REM2:><REM2:T1 = DOS batch file><REM2:T2 = File to get attribute from><REM2:T3 = File to store results><TVAR2:01:01:c:\temp\test.bat><TVAR2:02:01:c:\temp\xfer.zip><TVAR2:03:01:c:\temp\results.txt><REM2:><REM2:Run the batch file and wait for the results to be written><LAUNCHDEL2:0:01%T1%<PARAM>"%T2%" "%T3%"><WFREADY:000000:000005:000000%T3%><REM2:><REM2:Parse the results file><TVAR2:04:04:%T3%T><TMVAR2:21:04:00:001:000:%T2%><TMVAR2:01:04:00:000:000:><REM2:><REM2:Test for an "R"><IFVAR2:1:04:7:TR><TBOX4:T:4:CenterCenter000250000150:000:
%T2% is a read-only file><ELSE><TBOX4:T:4:CenterCenter000250000150:000:
%T2% is NOT a read-only file><ENDIF><MRETURN><REM2:>

You will, of course need to change the files to suit your own needs. A word of explanation about parsing the results file is in order. On my system the resulting line contains 11 spaces and/or attributes along with a fullpath filename no matter if you supply the fullpath or not. So I simply remove the filename from T4 and then trim it before testing for an "R".


I have attached the files to this post. Hope this helps!


Link to comment
Share on other sites

Noggin -


The values being passed to batch file %1 and %2 reside in the Parameters field of the Program Launch command ("%T2%" "%T3%"). Variables are handled in Macro Express by simple substitution much like a #DEFINE so what the batch file receives are actually the two literals "c:\temp\xfer.zip" and "c:\temp\results.txt". Then the batch file replaces the first and second parameters (%1 and %2) with the passed literals. Which results in:


attrib c:\temp\xfer.zip > c:\temp\results.txt


Not the quotation marks ("%T2%" "%T3%") are important if you are passing filenames with spaces in them.

Link to comment
Share on other sites

Hi Joe,


Thanks for the pointer. I had figured what the attrib statement had to be but could not see how %1 was directed to %T2%, ditto for %2. On the Direct Editor listing you posted it can be seen but is not obvious from the Scripting Editor listing (which is what I read).


The Help files don't seem very good in this area (Command Line/DOS/Batch operations). It is not clear in Help that the Program Parameters can be applied to basic DOS statements in this fashion. A few examples would be have been useful. Most of the Help is related to switches.

Link to comment
Share on other sites

Oh sure ... DOS programs like batch files are, after all, programs like any other program. This is really no different than calling any other MS program while passing it command line parameters. We are simply passing parameters to a "programmable" program ... something you create ... rather than a pre-written program like Excel, Word, and so forth.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...