Topics

Help with a Wizard?


John Shotsky
 

I'm not very proficient with wizards, and have come upon a need that I don't
know how to accomplish.

I want to present a list of filetypes found in a given folder to a user. I want
the user to pick one of them, which will then set a variable %Type%.

The working folder is ^%WorkFolder%, which holds the complete path to where the
files are located. The user's document is inside this folder, and is open, with
a .txt file type. If all the files in the work folder are .txt files, this
wizard is skipped, because the default type is .txt, and there is no need to use
a wizard unless it is to be changed.

So, the task is to inventory the file types in the workfolder, and just continue
on if they are all .txt files. Only when there are two or more filetypes is the
wizard needed.

The files with the proper Type will be merged into a single file, which will
then be opened and processed.

I've looked through several sample libraries but didn't see anything I could
adapt to this task. I do know how to create a list of all the files in the
folder, but that seems like overkill.

I could create a list of filetypes that are used in this system, then I'd need a
way to see if a given filetype is present by processing through them one by one.
I'm not sure how to see if there is a .mmf file type in the workfolder, for
example.

Does anyone have any ideas?

Regards,

John


Axel Berger
 

John Shotsky wrote:
Does anyone have any ideas?
John, as far as I can tell the task is easy, but you're on your own, so
it's a lot of work. I know you only need a very rough outline:
1) dir a list of all files, one per line
2) open and replace each line with ^$GetExt(FileName)$
3) sort
4) delete every line that's identical to the preceding one
5) convert into the format for a wizard
Done.

As always with me this approach is pedestrian and primitive. There will
certainly be a more elegant solution, but that wouldn't be the one I
instantly recognize and understand when coming back to it many months
later.


--
/¯\ 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, that is the one approach I was hoping to avoid, but clearly it is
a way. I did figure out how to see if a given filetype is in the workfolder, so
I can iterate through filetypes that are known about. There aren't many.
;==
:Find FileTypes
^!Set %InputFile%=^$GetDocName$
;Get the path with trailing \
^!Set %BasePath%=^$GetPath("^%InputFile%")$
;Set filetype to find
^!Set %FindType%=^%BasePath%*.mmf
;See if it is found
^!IfFileExist ^%FindType% Next ELSE NotMmf
^!Set %Type%=mmf
:NotMmf
;==
Regards,
John

-----Original Message-----
From: Clips@Notetab.groups.io <Clips@Notetab.groups.io> On Behalf Of Axel Berger
Sent: Thursday, April 30, 2020 11:47 AM
To: Clips@Notetab.groups.io
Subject: Re: [NTB-Clps] Help with a Wizard?

John Shotsky wrote:
Does anyone have any ideas?
John, as far as I can tell the task is easy, but you're on your own, so it's a
lot of work. I know you only need a very rough outline:
1) dir a list of all files, one per line
2) open and replace each line with ^$GetExt(FileName)$
3) sort
4) delete every line that's identical to the preceding one
5) convert into the format for a wizard
Done.

As always with me this approach is pedestrian and primitive. There will
certainly be a more elegant solution, but that wouldn't be the one I instantly
recognize and understand when coming back to it many months later.


--
/¯\ 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! --


Thomas Gruber Yahoo
 

Hi John, Axel,
1 modification of Axel‘s approach:
If you do a „dir /OE“ then you get the files sorted by extension (=file type). Then you can go through the list and just pick up the extension when it changes.
That way you only get a short list of all the different extensions.
Kind regards
Thomas (Computerhusky)

Am 30.04.2020 um 20:45 schrieb Axel Berger <Axel@...>:

John Shotsky wrote:
Does anyone have any ideas?
John, as far as I can tell the task is easy, but you're on your own, so
it's a lot of work. I know you only need a very rough outline:
1) dir a list of all files, one per line
2) open and replace each line with ^$GetExt(FileName)$
3) sort
4) delete every line that's identical to the preceding one
5) convert into the format for a wizard
Done.

As always with me this approach is pedestrian and primitive. There will
certainly be a more elegant solution, but that wouldn't be the one I
instantly recognize and understand when coming back to it many months
later.


--
/¯\ 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, Thomas,
Well, that is a good idea, but my next question is whether, once you have such a list of candidate files in a document, can you merge them all into a single file? That's ultimately what this is about - getting a bunch of loose files in to a single file. I guess I could concatenate them using a DOS command, but then the command window would also flash. I don't like seeing those flashes, but have not found a suitable approach to preventing them.
Regards,
John

-----Original Message-----
From: Clips@Notetab.groups.io <Clips@Notetab.groups.io> On Behalf Of Thomas Gruber Yahoo via groups.io
Sent: Thursday, April 30, 2020 12:22 PM
To: Clips@notetab.groups.io
Subject: Re: [NTB-Clps] Help with a Wizard?

Hi John, Axel,
1 modification of Axel‘s approach:
If you do a „dir /OE“ then you get the files sorted by extension (=file type). Then you can go through the list and just pick up the extension when it changes.
That way you only get a short list of all the different extensions.
Kind regards
Thomas (Computerhusky)

Am 30.04.2020 um 20:45 schrieb Axel Berger <Axel@...>:

John Shotsky wrote:
Does anyone have any ideas?
John, as far as I can tell the task is easy, but you're on your own,
so it's a lot of work. I know you only need a very rough outline:
1) dir a list of all files, one per line
2) open and replace each line with ^$GetExt(FileName)$
3) sort
4) delete every line that's identical to the preceding one
5) convert into the format for a wizard Done.

As always with me this approach is pedestrian and primitive. There
will certainly be a more elegant solution, but that wouldn't be the
one I instantly recognize and understand when coming back to it many
months later.


--
/¯\ 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! --



Axel Berger
 

John Shotsky wrote:
so
I can iterate through filetypes that are known about. There aren't many.
Yes, that makes it easier.

--
/¯\ 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! --


Axel Berger
 

John Shotsky wrote:
I guess I could concatenate them using a DOS command, but then the
command window would also flash. I don't like seeing those flashes,
You can read a whole file into a variable with ^$GetFileText(FileName)$ and
then append it to a destination file all within NT. This involves looping
and file access so can get slow when files number in the hundreds.

My normal use case is the other way round. I'm starting not with NT but
rather from Totalcommander by calling a batch and that batch opens NT. A
simple but very freqeuntly used example is this:

echo off
iff "%1" == "" then
dir /b /on * > 0a-Liter.txt
delay 1
F:\Winutil\NoteTab\NotePro.exe 0a-Liter.txt
else
dir /b /on * > %1
delay 1
F:\Winutil\NoteTab\NotePro.exe %1
endiff

or one calling a clip

call texclean
dir /b /a-d /on /s * > PDF.txt
char t2w PDF.txt
F:\Winutil\NoteTab\NotePro.exe /L="Functions:Format Filelist" PDF.txt
pause
texclean nosub

"texclean" is another DOS-batch and "char" a small Pascal program.


--
/¯\ 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! --


joy8388608
 

I feel this would be easy to do without looping in only a few lines of NT.

I would be happy to write it once I get to my computer (let me know) but my general thought is as follows

Collect all file names in the desired folder using getdosoutput (guessing at NT command name)

One regular expression replace to leave only the extensions

One sort command which can automatically remove duplicates

Examine the unique extensions remaining and call the wizard if necessary.

Joy


Axel Berger
 

"joy8388608 via groups.io" wrote:
I feel this would be easy to do without looping in only a few lines of NT.
I knew it. Our styles are very much at opposite ends of the spectrum.

Luckily my idea does not involve looping as such but quite a few
^!IfError NEXT ELSE SKIP_-1

A simple-minded replace will get only every second duplicate entry at one
go. Good enough for me. After eight iterations only every 256th is left.


--
/¯\ 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! --


Thomas Gruber Yahoo
 

hi Joy,
the outline below already gives a few interesting insights :-) - thanks for that.
particularly the „sort and remove duplicates“ - I wouldn’t even have searched for such a command in the Clip Script Help.
I must admit I’m not very familiar with the scripting language - have written only a few pretty simple scripts.

A completed version of what you outline below would be very interesting!

Concatenating the files is the next step then - easy enough by invoking a sequence of DOS commands (I would use Powershell and not „copy“ command, but that’s a personal preference) adding 1 file after another to the result - not really doable without a loop though. for a small number of files you could generate the copy command, ( copy file1.txt+file2.txt+file3.txt result.txt ) but that’s limited.

Axel, pulling a number of files into a variable sounds interesting, but what about the total size in case of big files and/or a reasonably large number? Wouldn’t that run out of memory?

Kind regards
Thomas

Am 01.05.2020 um 20:00 schrieb joy8388608 via groups.io <mycroftj=yahoo.com@groups.io>:

I feel this would be easy to do without looping in only a few lines of NT.

I would be happy to write it once I get to my computer (let me know) but my general thought is as follows

Collect all file names in the desired folder using getdosoutput (guessing at NT command name)

One regular expression replace to leave only the extensions

One sort command which can automatically remove duplicates

Examine the unique extensions remaining and call the wizard if necessary.

Joy



Axel Berger
 

"Thomas Gruber Yahoo via groups.io" wrote:
Axel, pulling a number of files into a variable sounds interesting,
but what about the total size in case of big files and/or a reasonably
large number? Wouldn’t that run out of memory?
That's not quite what I suggested and why I used the Append command. I'd
read the files one by one and only have in the variable. John's files can
be expected to be reasonably small.

N.B: ^!AppendToFile is a command I use quite often.


--
/¯\ 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
 

Yes, I think I still need help. Still working on it, and it seems to get worse the longer I work on it.
The fundamental requirement is to merge a bunch of text files into one file.
The file type of the wanted files needs to be established.
The list of files of that type needs to be presented to the user
The user is to deselect any files to exclude.
The now modified list of files is to be concatenated into a temporary file.
It sounds relatively simple, but managing NTB's awkward file commands is a less than satisfactory process.

Once the file type is known, a proper dos dir command (/b) piped to the clipboard would get the list easily.
Pasting the Dir into a new doc, the file names can be merged with '+' between them.
Then a doc type using the list should produce what is needed.
Seems that would be easier than trying to use NTB's VERY picky and poorly documented commands.
I'll work on getting the dos commands working so I can move on. May come back to this later and see if I can get it to work with NTB commands. Much to do.
Regards,
John

-----Original Message-----
From: Clips@Notetab.groups.io <Clips@Notetab.groups.io> On Behalf Of joy8388608 via groups.io
Sent: Friday, May 1, 2020 11:00 AM
To: Clips@Notetab.groups.io
Subject: Re: [NTB-Clps] Help with a Wizard?

I feel this would be easy to do without looping in only a few lines of NT.

I would be happy to write it once I get to my computer (let me know) but my general thought is as follows

Collect all file names in the desired folder using getdosoutput (guessing at NT command name)

One regular expression replace to leave only the extensions

One sort command which can automatically remove duplicates

Examine the unique extensions remaining and call the wizard if necessary.

Joy


joy8388608
 
Edited

This builds a wizard with all the unique extensions in a folder. I hope this gets you started.
I left the temp doc open. You can close it or use it farther in your clip.

Now I see you plan to present all files with the selected extension and let the user deselect one or more then concatenate the rest of the files into one, new file? Is that correct? Does order matter?

If so, how many files might there be? I can think of a way to do this nicely if there are not too many files. If there will be many, I can think of another way, but it's not nearly as nice but would work.

Let me know if you need more help and then explain a little better in more detail what you are trying to do.

Joy

; 2020/05/01 Get unique list of all extensions in a folder by Joy
^!Toolbar New Document
; Set folder
^!Set %WorkFolder%=C:\Users\qiuh2\Downloads
^!Set %theDosCommand%="dir "^%WorkFolder""
^$GetDosOutput("^%theDosCommand%" /B /A:-D /A:-H)$
; Remove all lines that do not contain a period
^!Replace "^[^.]*\R" >> "" RAWTS
; Remove all but the filename extensions
^!Replace "^.*\.(.+)$" >> "$1" RAWTS
^!Select ALL
; Remove duplicates
^!InsertText ^$StrSort("^$GetSelection$";False;True;True)$
; Remove empty lines at EOD
^!Replace "[\t\f\r\n\x20]*\Z" >> "" WRS
^!If ^$GetLineCount$>1 SHOW_WIZ
; just one ext
^!IfSame "^$GetLine$" "txt" DO_NOT_SHOW_WIZ

:SHOW_WIZ
^!Replace "\R" >> "\|" ASWTR
^!Set %SelectedExt%=^?{Select Ext=_^$GetText$}
^!Prompt User selected ^%SelectedExt%
:DO_NOT_SHOW_WIZ
^!Prompt Done