cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Questions about reading files in Mathcad

Iuri
1-Newbie

Questions about reading files in Mathcad

Hi,

I have a Mathcad 15 and I have a problem to read files that change the final part of their names but the beginning is always the same, what is the expression I use Mathcad to only recognize these files?

In batch we use the "*", but I'm struggling to find an operator in Mathcad to do the same function

9 REPLIES 9
RichardJ
19-Tanzanite
(To:Iuri)

If you go here: Extra Components.mcd there is a scripted component that will give you a list of files in a folder. Will that do what you want? If not, could you be more specific about the nature of the problem.

Iuri
1-Newbie
(To:RichardJ)

Richard thanks for the reply,

but what I want is simpler than that, I need to read files .dat that will be in the directory one at a time with the following structure: in_ [the date on which the file was generated].dat. Then read using any function of Mathcad I tried to write this file as in*.dat. But I do not know which operator can replace the "*" I've used.

LucMeekes
23-Emerald III
(To:Iuri)

Hi Iuri,

There is no operator "*", unfortunately. It must be done the hard way.

As a possible alternative to Richard's suggestion, you can check to see if the function Files() works in your Mathcad 15 (In MathCad 11 it does).

This function accepts 2 arguments:

- a path, like "C:\"

- a file attribute, like "a".

But the second argument is optional.

So if it works in mathcad 15, the expression:

Files("C:\Windows","d")=

Should give you an array of strings, each string representing one of the subdirectories of C:\Windows

And with Files("C:\")=

you should get a list of all files on the root of drive C:

In order to find the "In_*.dat" file, you should parse the array, using MathCad's string functions.

Note that Files() is not documented (at least not in Mathcad 11) and/but works to some extent: it generally shows only files that do have an attribute (a,d,h,r,s). Fortunately new files usually have the "a" atribute set.

But all the above is of no use to you if the function is not supported by mathcad 15....

Success!

Luc

Iuri
1-Newbie
(To:LucMeekes)

Thanks LucMeekes,

but unfortunately the function Files() is not supported in Mathcad 15.

RichardJ
19-Tanzanite
(To:Iuri)

but what I want is simpler than that, I need to read files .dat that will be in the directory one at a time with the following structure: in_ [the date on which the file was generated].dat. Then read using any function of Mathcad I tried to write this file as in*.dat. But I do not know which operator can replace the "*" I've used.

Based on what you say it's exectly what you want. It will give you a list of files, in a vector. Then you can use READPRN in a loop to read them in.

Iuri
1-Newbie
(To:RichardJ)

Richard,

I already had tried this code using the concat() function in this same way, but the function READPRN warns that it can not open the data file. So I think the Mathcad does not use the same Windows path to find files. I tried to run your file and also gave the same problem.

RichardJ
19-Tanzanite
(To:Iuri)

Please post a worksheet showing what you have done. One data file would be useful too. To post a file you need to click on "use advanced editor" at the top right.

Iuri
1-Newbie
(To:RichardJ)

I want to read this file in_file.dat as in*.dat because I receive every 24 hours this name over your date and then write another file with the current date, but the writing is the way I want, and only the lack reading the file.

RichardJ
19-Tanzanite
(To:Iuri)

You can't do it like that. READPRN does not recognize wildcards. If you don't know exactly what the filename is, then you have to use the scripted component to get the exact filename, and then use that filename.

Top Tags