Skip to main content
1-Visitor
June 27, 2016
Solved

Is it possible to point Mathcad to a directory and have it read all files?

  • June 27, 2016
  • 7 replies
  • 4085 views

I have a bunch of images I would like analyzed for a specific "shape_feature".  I would prefer not to have to point to each one individually.  I would like to write a little program (in Mathcad) that points to a directory, does the image processing and gets the "shape_feature" I want and then goes to the next image in the directory.  I think I know how to do this except I don't know how to have Mathcad point to a directory and look at all the files in the directory.  Any help would be appreciated.

Best answer by AlvaroDíaz

Hi Marcus.

With Mathcad 15 you can write a vbscript component. But I guess that is more easy to use a DOS command window with "dir *.jpg > names.txt", read "names.txt" into mathcad and use the string functions inside mathcad to recover the names.

Best regards.

Alvaro.

7 replies

12-Amethyst
June 27, 2016

Hi Marcus.

With Mathcad 15 you can write a vbscript component. But I guess that is more easy to use a DOS command window with "dir *.jpg > names.txt", read "names.txt" into mathcad and use the string functions inside mathcad to recover the names.

Best regards.

Alvaro.

mepp1-VisitorAuthor
1-Visitor
June 27, 2016

Thanks Alvaro for the insight,

I am using Mathcad Prime 3.1 and ideally I was hoping to keep everything in Mathcad but your suggestions may be workable for me.  Thanks for the suggestion.

Does anyone else have a potentially more direct suggestion?  Something that stays in Mathcad?

23-Emerald IV
June 27, 2016

You cannot write VBscript components in Prime, that feature is only available in the real Mathcad (version 15 and earlier)..

Also in the real mathcad is an undocumented function Files(), that allows two parameters, the first is a directory name (string), the second is an optional file type qualifier, directly linked to the 'attributes' of a file, such as R (read-only), H (hidden), D(directory) etc.

I don't know if that works in Prime.

At first sight: no

Also appears like there's a realer Mathcad: version11 knows the Files() function, Mathcad version 15 lost it.

Success!
Luc

mepp1-VisitorAuthor
1-Visitor
June 27, 2016

Hey Guys,

So I appreciate both your help and I think I am very close to getting what I need.  I ended up just using the DOS command window as I am not very savvy with C.

Ideally, what I want is to be able to point my Mathcad sheet to a directory full of images, it gives me the area of those images and compiles the different areas into a matrix.  I am very close to having this working but I have a programing error.  My program "Area" (in the worksheet) works as long as it only iterates once.  For example, if you change "while P does not equal NaN" to "while n<2" the program works.  I want the program to go through the list of files, getting the areas until "P equals NaN".  Can you see what is wrong with my program?  It is probably a silly error.  Thanks.

1-Visitor
June 27, 2016

To compare a variable to NaN, you have to use the function IsNaN() -- you cannot compare directly.  In your case, you'll obviously need to use the logical "not" comparison as well.

I did not check your program for any other errors.

mepp1-VisitorAuthor
1-Visitor
June 27, 2016

Thanks everyone.  I was able to get the Mathcad sheet working properly.  I appreciate the help.