Topics

How to find a file name


John Shotsky
 

Hi, all,

I have an interesting problem. Under clip control, I extract the contents of a
zip file. I know there is one file with an extension, in this case, of .mx2, but
I don't know the rest of the file name. Is there a way to figure out what the
rest of the file name is, given you know the path and the extension?

Regards,

John


Axel Berger
 

John Shotsky wrote:
Is there a way to figure out what the
rest of the file name is, given you know the path and the extension?
Offhand and not very elegant: Dir to a temp-file and ^!Find


--
/¯\ No | Dipl.-Ing. F. Axel Berger Tel: +49/ 221/ 7771 8067
\ / HTML | Roald-Amundsen-Straße 2a Fax: +49/ 221/ 7771 8069
 X in | D-50829 Köln-Ossendorf http://berger-odenthal.de
/ \ Mail | -- No unannounced, large, binary attachments, please! --


John Shotsky
 

Thanks, Axel!
Looks like the solution is to open *.mx2...had no idea that would work, but I tried it and it does work. Simple. So simple I didn't try it earlier... 😊
Regards,
John

-----Original Message-----
From: Clips@Notetab.groups.io <Clips@Notetab.groups.io> On Behalf Of Axel Berger
Sent: Saturday, June 20, 2020 4:21 PM
To: Clips@Notetab.groups.io
Subject: Re: [NTB-Clps] How to find a file name

John Shotsky wrote:
Is there a way to figure out what the
rest of the file name is, given you know the path and the extension?
Offhand and not very elegant: Dir to a temp-file and ^!Find


--
/¯\ No | Dipl.-Ing. F. Axel Berger Tel: +49/ 221/ 7771 8067
\ / HTML | Roald-Amundsen-Straße 2a Fax: +49/ 221/ 7771 8069
X in | D-50829 Köln-Ossendorf http://berger-odenthal.de
/ \ Mail | -- No unannounced, large, binary attachments, please! --


Art Kocsis
 

On 06-20-2020 15:33, John Shotsky wrote:
I have an interesting problem. Under clip control, I extract the contents of a
zip file. I know there is one file with an extension, in this case, of .mx2, but
I don't know the rest of the file name. Is there a way to figure out what the
rest of the file name is, given you know the path and the extension?
Why not simply use ^$GetFiles$ ?

^!Set %path%= {directory you want to search}
^!SetArray %mx2files%=^$GetFiles(^%path%;*.mx2)$

Art


John Shotsky
 

Because the system must figure out what the file name is and open it without
user intervention. But I did figure out that Open will accept wild cards, so
that made it easy.
Regards,
John

-----Original Message-----
From: Clips@Notetab.groups.io <Clips@Notetab.groups.io> On Behalf Of Art Kocsis
via groups.io
Sent: Saturday, June 20, 2020 9:17 PM
To: Clips@Notetab.groups.io
Subject: Re: [NTB-Clps] How to find a file name

On 06-20-2020 15:33, John Shotsky wrote:
I have an interesting problem. Under clip control, I extract the
contents of a zip file. I know there is one file with an extension, in
this case, of .mx2, but I don't know the rest of the file name. Is
there a way to figure out what the rest of the file name is, given you
know the path and the extension?
Why not simply use ^$GetFiles$ ?

^!Set %path%= {directory you want to search} ^!SetArray
%mx2files%=^$GetFiles(^%path%;*.mx2)$

Art


Axel Berger
 

John Shotsky wrote:
Why not simply use ^$GetFiles$ ?
Because the system must figure out what the file name is and open it without
user intervention.
Yes of course. What Art meant, but didn't say explicitly because it's
obvious, is that you then have to inspect the result and extract the full
name. That suggestion is similar, if much better, to mine.

Of course your own solution is the best and easiest, but ours would have
worked too.


--
/¯\ No | Dipl.-Ing. F. Axel Berger Tel: +49/ 221/ 7771 8067
\ / HTML | Roald-Amundsen-Straße 2a Fax: +49/ 221/ 7771 8069
 X in | D-50829 Köln-Ossendorf http://berger-odenthal.de
/ \ Mail | -- No unannounced, large, binary attachments, please! --


Art Kocsis
 

-----Original Message-----
On 06-20-2020 15:33, John Shotsky wrote:
I have an interesting problem. Under clip control, I extract the
contents of a zip file. I know there is one file with an extension, in
this case, of .mx2, but I don't know the rest of the file name. Is
there a way to figure out what the rest of the file name is, given you
know the path and the extension?
On 06-20-2020 21:16, Art Kocsis wrote:
Why not simply use ^$GetFiles$ ?

^!Set %path%= {directory you want to search}
^!SetArray %mx2files%=^$GetFiles(^%path%;*.mx2)$
On 06-21-2020 05:20, John Shotsky wrote:
Because the system must figure out what the file name is and open it without
user intervention. But I did figure out that Open will accept wild cards, so
that made it easy.
I was trying to be a bit facetious but I guess you didn't catch that.
I didn't explain the details as I assumed you were more literate with NTB and Windows file functions and would read the help file if not. My assumption was wrong so I will fill in the blanks for you:

You stated that you had extracted the contents of a zip file to an (implied) known Windows folder and wanted to determine the name only of the file with an mx2 extension.

The ^$GetFiles$ NTB function returns a fully qualified list of file names subject to the argument filters. In my example this is: all files in folder "^%path%" with extension "mx2" sorted in alphabetical order (default).

The files are NOT opened nor must the system "figure out what the file name is". The file system blindly scans the specified folder (technically the NTFS $MFT file tree), and returns all file names with a mx2 extension.

The ^$GetName$ NTB function extracts the name only portion of a filename (without the path or extension)
The ^$GetFileName$ function is similar but includes the extension as well.

So the complete answer would be:

^!Set %path%= {path to extracted ZIP files}
^!SetArray %mx2files%=^$GetFiles("^%path%";*.mx2)$
^!Set %mx2name%=^$GetName("^%mx2files1%")$ [file name only]
OR
^!Set %mx2name%=^$GetFileName("^%mx2files1%")$ [file name + extension]

So two or three lines of code satisfies your stated request. It doesn't get much simpler than that for your stated request. However, your comment about wild cards and Open implies that obtaining the file name was not your real goal. Your original request was misleading.

Art